-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Map Key Child Object
PostPosted: Wed Feb 18, 2009 11:26 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
I'm using Hibernate 3.3.1GA.

My problem is I have a parent class, with a map of child objects. The child objects have relation to another object. I need the index in the map to be a property of the child object's relation property. For instance:

public class Parent {
Map<String, Child> getChildren() {...}
}

public class Child {
public SomeOtherObject getOtherObject() {...}
}

public class SomeOtherObject {
public String getName() {...}
}

I want the index in the children map property on the Parent object to be the name property on the SomeOtherObject. Is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 1:42 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Can you post the relevant mappings

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:07 am 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
<class catalog="someDB" name="Parent" table="Parents">
...
<map cascade="all" catalog="someDB" lazy="true" name="children"
sort="unsorted" table="Children">
<key column="ParentID"/>
<key column="Name"/>
<one-to-many class="Child"/>
</map>
</class>

<class catalog="someDB" name="Child" table="Children">
...
<many-to-one class="SomeOtherObject" column="OtherObjectID" name="otherObject"/>
</class>

<class catalog="someDB" name="SomeOtherObject" table="OtherObjects">
...
<property generated="never" lazy="false" name="name" type="string">
<column name="Name" not-null="true" />
</property>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:41 am 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
I figured it out using a formula:

<map cascade="all" catalog="someDB" lazy="true" name="children"
sort="unsorted" table="Children">
<key column="ParentID"/>
<map-key column="Name" formula="(select o.Name from OtherObjects o where o.OtherObjectID = OtherObjectID) as Name"/>
<one-to-many class="Child"/>
</map>
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.