In this paper we discuss how metaphors for supporting user interaction with multimedia databases can be automatically generated. The work presented is a further step in the development of Virgilio, a Virtual Reality (VR) based system that has been designed to be a general purpose exploration tool for highly structured data. Virgilio visualizes the results of a query to a database by generating VR scenes, that exploit appropriate metaphors in order to take advantage of common knowledge about real world objects, thus reducing the cognitive load in the process of information assimilation. We analyze two specific components of the Virgilio architecture, the Query Management Tool and the Metaphor Definition Tool, and we identify a completely automatic procedure to define the metaphor that will be exploited in the construction of the VR scene. The implementation of this procedure exploits the backtracking search strategy of Prolog interpreters to solve a typical constraint satisfaction prob...