-->
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.  [ 8 posts ] 
Author Message
 Post subject: MappingException: bug in initComponentPropertyPaths
PostPosted: Wed Dec 03, 2003 5:41 pm 
Newbie

Joined: Wed Dec 03, 2003 5:23 pm
Posts: 7
Hi,

I'm very new, so please bear with me. I've got two tables
user_groups and user_group_hierarchies. The later has two
foreign keys (parent_id, child_id) to the primary key of the
former (user_groups) table. This allows user_groups to be
placed in a tree structure. I'm trying to return the parent_id
as part of the user_group data when I query for user_groups.
I thought to make a one-to-one association between the
user_group and the child_id in the hierarchy table. My current
arrangement is throwing an exception in hibernate code (I'm
using 2.1rc1). Details of my situation are below.

A couple of things occur to me: (a) I'm doing
this one-to-one thing wrong; (b) the association should be
another kind of association; (c) possibility of adding a parent_id
to the user_groups table; and (d) waiting for a hibernate
bug to be fixed.

Thanks for any help.
-Brandon

My hibernate descriptor file looks like this:

<class name="UserGroupEntity"
table="USER_GROUPS" dynamic-update="true">

<id name="id" column="id" type="long">
<generator class="sequence">
<param name="sequence">security_seq</param>
</generator>
</id>

<property name="name" column="NAME" type="string" />
<property name="description" column="DESCR" type="string" />
<property name="path" column="PATH" type="string" />

<one-to-one
name = "parent"
class = "UserGroupHierarchyEntity"
cascade = "none"
property-ref = "childGroupId"
/>

</class>

<class name="UserGroupHierarchyEntity"
table="USER_GROUP_HIERARCHIES" >

<composite-id >
<key-property name="parentGroupId" />
<key-property name="childGroupId" />
</composite-id >

<property name="parentGroupId" column="PARENT_GROUP_ID" type="long"
insert="false" update="false" />
<property name="childGroupId" column="CHILD_GROUP_ID" type="long"
insert="false" update="false"/>

</class>


When I run this I get an exception:

[2003-12-03 15:41:19,564] ERROR [STDERR ] net.sf.hibernate.MappingException: bug in initComponentPropertyPaths
at net.sf.hibernate.persister.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:140)
at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:111)
at net.sf.hibernate.persister.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:80)
at net.sf.hibernate.persister.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:503)
at net.sf.hibernate.persister.EntityPersister.postInstantiate(EntityPersister.java:112)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:155)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:720)

This has an embedded exception which looks like this:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at net.sf.hibernate.util.ArrayHelper.slice(ArrayHelper.java:61)
at net.sf.hibernate.persister.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:135)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 7:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Remove
Code:
<property name="parentGroupId" column="PARENT_GROUP_ID" type="long"
insert="false" update="false" />
<property name="childGroupId" column="CHILD_GROUP_ID" type="long"
insert="false" update="false"/>


You already mapped parentGroupId; and childGroupId java properties in the composite-id

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 9:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, you can't map the same property twice!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 11:21 am 
Newbie

Joined: Wed Dec 03, 2003 5:23 pm
Posts: 7
I was trying a bunch of different things to see how they worked.
I'm not exactly sure, but I think I had the properties in addition
to the composite id because I was getting a error that said that
it couldn't find the properties.

My real question is: Is the one-to-one association the right thing
to use in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 3:33 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 3:27 pm
Posts: 21
fyi, this exception also occurs if you have a column in your table named the same as the table. Needless to say it's probably pretty weird to have a column named the same as the table and we ended up renaming ours so that this isn't an issue. It did however cause me to bark up the wrong tree for awhile trying to figure out what was going.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 3:51 pm 
Newbie

Joined: Wed Dec 03, 2003 5:23 pm
Posts: 7
I ended up using formula properties. That worked fairly well.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 6:19 pm 
Newbie

Joined: Mon Dec 08, 2003 1:54 pm
Posts: 4
Would you mind posting the mapping files you ended up with?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 7:11 pm 
Newbie

Joined: Wed Dec 03, 2003 5:23 pm
Posts: 7
As the doc says, you have purely derived properties based on a sql query. Two I'm using look like this:

<property name="childCount" insert="false" update="false"
formula=
"(select count(*) from user_group_hierarchies ugh where ugh.parent_group_id = id)"
/>

<property name="parentId" insert="false" update="false"
formula=
"(select ugh.parent_group_id from user_group_hierarchies ugh where ugh.child_group_id = id)"
/>

where id is the column name of the primary key of my class. Hibernate places those queries as column subqueries in the query it constructs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.