-->
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.  [ 1 post ] 
Author Message
 Post subject: bidirectional many-to-many returning null objects
PostPosted: Tue Jun 13, 2006 12:10 pm 
Newbie

Joined: Wed Dec 07, 2005 10:05 pm
Posts: 2
When I use the below mapping I get null results back from the getParents() method if parents is mapped with inverse="true", while the getChildren() method returns accurate results.

If I change so that children is mapped as inverse="true" I get the opposite. getParents() return accurate results and getChildren() returns null values. See last row in log for an example of getParents(). Reading the log seems to return 2 objects, but the method call lists 6 result where 5 are null.

Running the same query inside of MySQL returns correct result.

Hibernate version:
3.1.3

Mapping documents:
<class name="MyObject" dynamic-update="true" dynamic-insert="true" table="objects" abstract="true" lazy="false">
<id name="id" type="long" unsaved-value="null" column="id">
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" column="version"/>
<property name="guid" type="string" column="guid"/>
<property name="name" type="string" column="name"/>
<property name="type" type="string" column="type"/>
<list name="parents" table="object_links" cascade="none" inverse="true">
<key column="child_id" not-null="true"/>
<list-index>
<column name="sort_order" not-null="true"/>
</list-index>
<many-to-many column="parent_id" entity-name="com.elanders.cn.cms.model.CmsObject"/>
</list>
<list name="children" table="object_links" cascade="all">
<key column="parent_id" not-null="true"/>
<list-index>
<column name="sort_order" not-null="true"/>
</list-index>
<many-to-many column="child_id" entity-name="com.elanders.cn.cms.model.CmsObject"/>
</list>
</class>
...
joined subclasses removed
...

Code between sessionFactory.openSession() and session.close():
object.getChildren();
object.getParents();

Name and version of the database you are using:
MySQL 5.0.19

The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hibernate: select parents0_.child_id as child1_1_, parents0_.parent_id as parent2_1_, parents0_.sort_order as sort3_1_, cmsobject1_.id as id2_0_, cmsobject1_.version as version2_0_, cmsobject1_.guid as guid2_0_, cmsobject1_.name as name2_0_, cmsobject1_.type as type2_0_, cmsobject1_1_.name as name4_0_, cmsobject1_2_.name as name5_0_, cmsobject1_2_.short_name as short3_5_0_, cmsobject1_2_.password as password5_0_, cmsobject1_2_.network as network5_0_, cmsobject1_2_.home as home5_0_, cmsobject1_2_.email as email5_0_, cmsobject1_3_.name as name6_0_, cmsobject1_4_.name as name7_0_, cmsobject1_4_.short_name as short3_7_0_, cmsobject1_4_.password as password7_0_, cmsobject1_4_.network as network7_0_, cmsobject1_4_.home as home7_0_, cmsobject1_4_.email as email7_0_, cmsobject1_5_.name as name8_0_, cmsobject1_5_.url as url8_0_, cmsobject1_6_.name as name9_0_, cmsobject1_6_.bit_value as bit3_9_0_, cmsobject1_7_.name as name10_0_, cmsobject1_7_.permission_value as permission3_10_0_, cmsobject1_8_.name as name11_0_, cmsobject1_8_.assigned_type as assigned3_11_0_, cmsobject1_8_.default_name as default4_11_0_, cmsobject1_8_.constructor_class as construc5_11_0_, cmsobject1_8_.show_in_tree as show6_11_0_, cmsobject1_8_.is_inline_object as is7_11_0_, cmsobject1_8_.can_nest_self as can8_11_0_, cmsobject1_8_.auto_create as auto9_11_0_, cmsobject1_8_.display_scope as display10_11_0_, cmsobject1_8_.display_mode as display11_11_0_, cmsobject1_8_.display_page as display12_11_0_, cmsobject1_8_.edit_page as edit13_11_0_, case when cmsobject1_3_.object_id is not null then 3 when cmsobject1_4_.object_id is not null then 4 when cmsobject1_1_.object_id is not null then 1 when cmsobject1_2_.object_id is not null then 2 when cmsobject1_5_.object_id is not null then 5 when cmsobject1_6_.object_id is not null then 6 when cmsobject1_7_.object_id is not null then 7 when cmsobject1_8_.object_id is not null then 8 when cmsobject1_.id is not null then 0 end as clazz_0_ from object_links parents0_ left outer join objects cmsobject1_ on parents0_.parent_id=cmsobject1_.id left outer join structures cmsobject1_1_ on cmsobject1_.id=cmsobject1_1_.object_id left outer join actors cmsobject1_2_ on cmsobject1_.id=cmsobject1_2_.object_id left outer join groups cmsobject1_3_ on cmsobject1_.id=cmsobject1_3_.object_id left outer join users cmsobject1_4_ on cmsobject1_.id=cmsobject1_4_.object_id left outer join modules cmsobject1_5_ on cmsobject1_.id=cmsobject1_5_.object_id left outer join permissions cmsobject1_6_ on cmsobject1_.id=cmsobject1_6_.object_id left outer join roles cmsobject1_7_ on cmsobject1_.id=cmsobject1_7_.object_id left outer join prototypes cmsobject1_8_ on cmsobject1_.id=cmsobject1_8_.object_id where parents0_.child_id=?
2006-06-13 23:57:58,375 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - binding '32' to parameter: 1
2006-06-13 23:57:58,375 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - result set contains (possibly empty) collection: [com.elanders.cn.cms.model.CmsObject.parents#32]
2006-06-13 23:57:58,375 DEBUG org.hibernate.engine.CollectionLoadContext - uninitialized collection: initializing
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - processing result set
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - result set row: 0
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '26' as column: id2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.elanders.cn.cms.model.CmsObject#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '1' as column: clazz_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [com.elanders.cn.cms.model.Structure#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [com.elanders.cn.cms.model.Structure#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '0' as column: version2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning '3DA0A241-CF38-BCE4-278D-BD07D617B344' as column: guid2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'Permissions' as column: name2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'Permissions' as column: type2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'Permissions' as column: name4_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.engine.TwoPhaseLoad - Version: 0
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '32' as column: child1_1_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - found row of collection: [com.elanders.cn.cms.model.CmsObject.parents#32]
2006-06-13 23:57:58,375 DEBUG org.hibernate.engine.CollectionLoadContext - reading row
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '26' as column: parent2_1_
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [com.elanders.cn.cms.model.CmsObject#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [com.elanders.cn.cms.model.CmsObject#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [com.elanders.cn.cms.model.CmsObject#26]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '5' as column: sort3_1_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - result set row: 1
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '35' as column: id2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.elanders.cn.cms.model.CmsObject#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '1' as column: clazz_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - Initializing object from ResultSet: [com.elanders.cn.cms.model.Structure#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Hydrating entity: [com.elanders.cn.cms.model.Structure#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '0' as column: version2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'F5D621FC-944A-C73A-4C66-762AD5A28B59' as column: guid2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'Role Permissions' as column: name2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'RolePermissions' as column: type2_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.StringType - returning 'Role Permissions' as column: name4_0_
2006-06-13 23:57:58,375 DEBUG org.hibernate.engine.TwoPhaseLoad - Version: 0
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '32' as column: child1_1_
2006-06-13 23:57:58,375 DEBUG org.hibernate.loader.Loader - found row of collection: [com.elanders.cn.cms.model.CmsObject.parents#32]
2006-06-13 23:57:58,375 DEBUG org.hibernate.engine.CollectionLoadContext - reading row
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.LongType - returning '35' as column: parent2_1_
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [com.elanders.cn.cms.model.CmsObject#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [com.elanders.cn.cms.model.CmsObject#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.event.def.DefaultLoadEventListener - resolved object in session cache: [com.elanders.cn.cms.model.CmsObject#35]
2006-06-13 23:57:58,375 DEBUG org.hibernate.type.IntegerType - returning '5' as column: sort3_1_
2006-06-13 23:57:58,453 DEBUG org.hibernate.loader.Loader - done processing result set (2 rows)
2006-06-13 23:57:58,453 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
2006-06-13 23:57:58,453 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-06-13 23:57:58,453 DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2006-06-13 23:57:58,453 DEBUG org.hibernate.loader.Loader - total objects hydrated: 2
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.elanders.cn.cms.model.Structure#26]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.parents#26]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.children#26]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.nodes#26]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.elanders.cn.cms.model.Structure#26]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.elanders.cn.cms.model.Structure#35]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.parents#35]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.children#35]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[com.elanders.cn.cms.model.CmsObject.nodes#35]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.elanders.cn.cms.model.Structure#35]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - 1 collections were found in result set for role: com.elanders.cn.cms.model.CmsObject.parents
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - collection fully initialized: [com.elanders.cn.cms.model.CmsObject.parents#32]
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.CollectionLoadContext - 1 collections initialized for role: com.elanders.cn.cms.model.CmsObject.parents
2006-06-13 23:57:58,453 DEBUG org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
2006-06-13 23:57:58,453 DEBUG org.hibernate.loader.Loader - done loading collection
2006-06-13 23:57:58,453 DEBUG org.hibernate.event.def.DefaultInitializeCollectionEventListener - collection initialized
2006-06-13 23:57:58,453 DEBUG com.elanders.cn.cms.service.impl.CmsManagerImpl - OBJECT PARENTS: [null, null, null, null, null, Role Permissions (35)]


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

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.