-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: XML-Mapping: set mit where condition über mehrere tabellen
PostPosted: Fri Oct 20, 2006 7:37 am 
Newbie

Joined: Fri Oct 20, 2006 7:20 am
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 9:57 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Lege vielleicht ein Mapping auf einen View oder ein Mapping mit einer Query an, so dass die Zieltabelle bereits die gejointen Daten enthält.

Und dazu einfach eine normale Set Beziehung.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.