From: Michael R. (JIRA) <no...@at...> - 2006-07-31 21:07:14
|
A combination of Criteria, fetch="join", and possibly "many-to-many" mapping creates wrong number of objects. ------------------------------------------------------------------------------------------------------------- Key: HHH-1960 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1960 Project: Hibernate3 Type: Bug Components: query-criteria Versions: 3.1.3 Environment: Version 3.1.3, all databases. Reporter: Michael Reviakin Add following method to the EventManager class from the tutorial: List findPerson(String lastName) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); List result = session.createCriteria(Person.class). add(Restrictions.eq("lastName", lastName)). list(); session.getTransaction().commit(); return result; } Create at least one Person and two Events, add Person to both Events. call System.out.println(eventManager.findPerson(person.getLastName()).size()); The output should be 1. Change Person.hbm.xml file, add fetch="join" attribute to the events mapping as following: <set name="events" table="PERSON_EVENT" fetch="join"> <key column="PERSON_ID"/> <many-to-many column="EVENT_ID" class="events.Event"/> </set> Run the same test, the output will be 2. Change "functional" part of the findPerson method to: List result = session.createQuery("from Person where lastName = :lastName"). setString("lastName", lastName). list(); Run the same test, the output will be 1 again. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |