-->
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: maps of maps in Hibernate
PostPosted: Fri Dec 22, 2006 12:58 am 
Newbie

Joined: Fri Dec 22, 2006 12:35 am
Posts: 5
Hi,
I am a newbie in Hiberante and would like to ask about the option to create maps of maps.

my data model is create of several layers, each layer may have 0 to N children.

i currently imlplement it as maps of maps, and use recursion to go down (never up) to the data i need and retrieve it.

i would like to know:
1. is there some example code (apart from the very lean one in section 4.4 (http://www.hibernate.org/hib_docs/v3/reference/en/html/persistent-classes.html). for this kind of model? what about recursivly going through the object model?
or maybe some kind of easier solution to my problem?

2. how can i implement one to many assosiation, it seems i need a getter for that and my model does not support getters and setters

3. is it possible to create the mapping through data driven process (i saw the option to do it using configuration-cfg.getClassMapping, any code examples for that?)


i currently implemented a bi directional assosiaction from a class called Temp_Hiber1 the parent to Temp_Hber2 the children but i can't use the set since it requires a getter. here are my mappings:
<hibernate-mapping>
<class name="b.hibernate.TempHiber1" table="TEMP_HIBER1" schema="B">
<id name="key" type="java.lang.String">
<column name="KEY" length="6" />
<generator class="assigned" />
</id>
<property name="value" type="java.lang.String">
<column name="VALUE" length="20" />
</property>

<set name="children"
inverse="true"
lazy="false"
cascade="all">
<key column="PARENT"/>
<one-to-many class="b.hibernate.TempHiber2"/>
</set>

</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="b.hibernate.TempHiber2" table="TEMP_HIBER2" schema="B">
<id name="key" type="java.lang.String">
<column name="KEY" length="6" />
<generator class="assigned" />
</id>
<property name="value" type="java.lang.String">
<column name="VALUE" length="6" />
</property>
<many-to-one name="parent"
column="PARENT"
class="b.hibernate.TempHiber1"/>
</class>
</hibernate-mapping>

and my intial test code is:
TempHiber2DAO hiberDao = new TempHiber2DAO();
Transaction transaction = hiberDao.getSession().beginTransaction();
Session s = hiberDao.getSession();

// Create a child Hiber2
Map child = new HashMap();
child.put("key", "Hi5");
child.put("value", "Hi5");

// Create a parent Hiber1
Map parent = new HashMap();

parent.put("key", "5");
parent.put("value", "5");

// Link both
child.put("parent", parent);//(Long)

// Save both
s.save("b.hibernate.TempHiber2", child);
s.save("b.hibernate.TempHiber1", parent);

transaction.commit();
s.close();

//my current exception is:
org.hibernate.PropertyNotFoundException: Could not find a getter for children in class.

Thanks,


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.