From: Urberg, J. <ju...@ve...> - 2002-08-08 17:34:57
|
I updated from cvs this morning. I tried out collection caching and am not getting the results I expect. Here's some detail: I have AddresseeGroups which are made up of AddresseeGroupEntrys of either other AddresseeGroups or Staff. AddresseeGroup --> AddresseeGroupEntry --> Staff ^ | | | --------------------- I've mapped it like this (I've left out the package names to make it more readable): <class name="AddresseeGroup" table="addressee_group"> <id name="id" column="id" type="long"> <generator class="native"/> </id> <property name="description"/> <set role="entries"> <key column="addressee_group_owner_id"/> <one-to-many class="AddresseeGroupEntry"/> </set> </class> <class name="AddresseeGroupEntry" table="addressee_group_entry"> <id name="id" column="id" type="long"> <generator class="native"/> </id> <many-to-one name="owner" class="AddresseeGroup" column="addressee_group_owner_id" cascade="none" outer-join="true"/> <many-to-one name="groupEntry" class="AddresseeGroup" column="addressee_group_entry_id" cascade="none" outer-join="true"/> <many-to-one name="staffEntry" class="StaffImpl" column="staff_id" cascade="none" outer-join="true"/> </class> <class name="StaffImpl" table="staff"> <!-- proxy="Staff"> --> <id name="id" column="id" type="long"> <generator class="native"/> </id> <property name="staffId" column="staffid"/> <component name="name" class="Name"> <property name="firstName" column="firstname"/> <property name="middleInitial" column="middleinitial"/> <property name="lastName" column="lastname"/> </component> <property name="privilegeLevel" column="privilege_level"/> </class> So I figure I can do the following: session.find("from staff in class StaffImpl"); session.find("from age in class AddresseeGroupEntry"); List groups = dao.currentSession.find("from ag in class AddresseeGroup"); And I would expect 3 SQL statements with all the many-to-ones and collections should get resolved from the cache. My first shot at this returned: cirrus.hibernate.HibernateException: You tried to persist an object with a reference to a transient instance - save the transient instance first at cirrus.hibernate.type.PersistentObjectType.getID(PersistentObjectType.java:9 4) at cirrus.hibernate.type.PersistentObjectType.nullSafeSet(PersistentObjectType. java:79) at cirrus.hibernate.impl.ClassPersister.dehydrate(ClassPersister.java:677) at cirrus.hibernate.impl.ClassPersister.update(ClassPersister.java:862) at cirrus.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:21) at cirrus.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:1721) at cirrus.hibernate.impl.SessionImpl.flush(SessionImpl.java:1701) at cirrus.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1057) at cirrus.hibernate.impl.SessionImpl.find(SessionImpl.java:836) at cirrus.hibernate.impl.SessionImpl.find(SessionImpl.java:824) at cirrus.hibernate.impl.SessionImpl.find(SessionImpl.java:816) Why would that happen? Then, I added session.suspendFlushes() before the queries. It generated the following 9 SQLs: Hibernate: SELECT staff.id, staff.staffid, staff.firstname, staff.middleinitial, staff.lastname, staff.privilege_level FROM staff staff Hibernate: SELECT age.id, age.addressee_group_owner_id, age.addressee_group_entry_id, age.staff_id FROM addressee_group_entry age Hibernate: SELECT addressee_group0.id AS id, addressee_group0.description AS description FROM addressee_group addressee_group0 WHERE addressee_group0.id = ? Hibernate: SELECT y.id, y.addressee_group_owner_id, y.addressee_group_entry_id, y.staff_id FROM addressee_group_entry y, addressee_group x WHERE x.id = y.addressee_group_owner_id AND (x.id=? ) Hibernate: SELECT addressee_group0.id AS id, addressee_group0.description AS description FROM addressee_group addressee_group0 WHERE addressee_group0.id = ? Hibernate: SELECT y.id, y.addressee_group_owner_id, y.addressee_group_entry_id, y.staff_id FROM addressee_group_entry y, addressee_group x WHERE x.id = y.addressee_group_owner_id AND (x.id=? ) Hibernate: select id from addressee_group_entry where addressee_group_owner_id = ? Hibernate: select id from addressee_group_entry where addressee_group_owner_id = ? Hibernate: SELECT ag.id, ag.description FROM addressee_group ag Then I commented out the first two finds and suspendFlushes, so I now have just this: List groups = dao.currentSession.find("from ag in class AddresseeGroup"); And I get the following 9 slightly different SQLs: Hibernate: SELECT ag.id, ag.description FROM addressee_group ag Hibernate: SELECT y.id, y.addressee_group_owner_id, y.addressee_group_entry_id, y.staff_id FROM addressee_group_entry y, addressee_group x WHERE x.id = y.addressee_group_owner_id AND (x.id=? ) Hibernate: SELECT staff0.id AS id, staff0.staffid AS staffid, staff0.firstname AS firstname, staff0.middleinitial AS middleinitial, staff0.lastname AS lastname, staff0.privilege_level AS privilege_level FROM staff staff0 WHERE staff0.id = ? Hibernate: SELECT staff0.id AS id, staff0.staffid AS staffid, staff0.firstname AS firstname, staff0.middleinitial AS middleinitial, staff0.lastname AS lastname, staff0.privilege_level AS privilege_level FROM staff staff0 WHERE staff0.id = ? Hibernate: SELECT staff0.id AS id, staff0.staffid AS staffid, staff0.firstname AS firstname, staff0.middleinitial AS middleinitial, staff0.lastname AS lastname, staff0.privilege_level AS privilege_level FROM staff staff0 WHERE staff0.id = ? Hibernate: SELECT addressee_group0.id AS id, addressee_group0.description AS description FROM addressee_group addressee_group0 WHERE addressee_group0.id = ? Hibernate: SELECT y.id, y.addressee_group_owner_id, y.addressee_group_entry_id, y.staff_id FROM addressee_group_entry y, addressee_group x WHERE x.id = y.addressee_group_owner_id AND (x.id=? ) Hibernate: select id from addressee_group_entry where addressee_group_owner_id = ? Hibernate: select id from addressee_group_entry where addressee_group_owner_id = ? Is this what I should expect? Is there other settings I need to make? Thanks, John |