Wie kann man in der XML-Mapping-Definition in der <set> Definition eine where-Clause angeben, die über mehrere Tabellen geht, also einen Join benötigt?
Aufgabe: das Set eventUsers soll gefüllt werden, aber nur mit Einträgen die eventUser.event.deleted = 0 haben.
Die Set-Definition:
<set name="eventUsers" table="events_users" lazy="true" inverse="true" order-by="user_id"
where="event_id = events.id AND events.deleted=0">
<key column="user_id" not-null="true"/>
<one-to-many class="amiando.EventUser"/>
</set>
Problem: Hibernate erkennt nicht, dass ein Join auf events nötig ist. Wie kann ich das mitteilen?
Er wirft dann folgende Fehlermeldung:
2006-10-20 13:34:16,031 DEBUG [org.hibernate.util.JDBCExceptionReporter] - could not initialize a collection: [amiando.User.eventUsers#18] [select eventusers0_.user_id as user3_1_, eventusers0_.id as id1_, eventusers0_.id as id0_, eventusers0_.event_id as event2_16_0_, eventusers0_.user_id as user3_16_0_, eventusers0_.eventRole as eventRole16_0_, eventusers0_.friendCount as friendCo5_16_0_, eventusers0_.comment as comment16_0_, eventusers0_.name as name16_0_, eventusers0_.mobile as mobile16_0_, eventusers0_.picIdent as picIdent16_0_
from events_users eventusers0_ where
eventusers0_.event_id = events.id AND events.deleted=0 and eventusers0_.user_id=? order by eventusers0_.user_id]
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'events.id' in 'where clause'
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3
Name and version of the database you are using: MySQL