juanignaciosl wrote:
I have a legacy database which doesn't keep referential integrity: there are some columns which are "almost" a FK: they are supposed to reference another table row, but it's not always true (sometimes it has a value but referenced row doesn't exist).
Couldn't you 'clean up' the data first? What does it mean then if a column has a value AND the referenced row does not exist?
That aside - Hibernate allows you to customize the SQL used for loading entities and collections. See for example
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querysql-load. The book
Java Persistence with Hibernate covers this topic in more detail and gives a lot of other valuable tips when working with legacy databases.
Personally, I would try to investigate first the option of a database cleanup or maybe even schema modification.
Good luck :)
--Hardy