-->
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.  [ 6 posts ] 
Author Message
 Post subject: Traversing the object graphs
PostPosted: Mon Apr 26, 2004 2:57 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
I have 2 classes,

An Employee has an Office. A 1 to 1 relationship.

So, after middlegen, hbm2java I ended up with 1 Employee and 1 Office POJO.

Employee e = new Employee();
e.setOffice(new Office());

Then I used the Hibernate session to save Employee. The Employee got created successfully, but the Office did not get created. Is there a way to make Hibernate traveser the object graph or do I have to do the traversal myself? Thanks.


Top
 Profile  
 
 Post subject: Re: Traversing the object graphs
PostPosted: Mon Apr 26, 2004 3:15 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Mapping files:

- <class name="om.Employee" table="Employee" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" optimistic-lock="version">
- <id name="employeeOid" type="java.lang.Integer" column="employeeOid" unsaved-value="null">
<generator class="native" />
</id>
<property name="locale" type="java.lang.String" column="locale" not-null="true" length="64" unique="false" update="true" insert="true" />

<one-to-one name="Office" class="om.Office" outer-join="auto" constrained="false" />
</class>


- <class name="om.Office" table="Office" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" optimistic-lock="version">

- <id name="employeeOid" type="java.lang.Integer" column="employeeOid" unsaved-value="null">
<generator class="native" />
</id>

<one-to-one name="Employee" class="om.Employee" outer-join="auto" constrained="true" />
</class>



Acco Lade wrote:
I have 2 classes,

An Employee has an Office. A 1 to 1 relationship.

So, after middlegen, hbm2java I ended up with 1 Employee and 1 Office POJO.

Employee e = new Employee();
e.setOffice(new Office());

Then I used the Hibernate session to save Employee. The Employee got created successfully, but the Office did not get created. Is there a way to make Hibernate traveser the object graph or do I have to do the traversal myself? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 3:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
set cascade="save-update" or higher on your association.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 3:51 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
:-) I set default-cascade="save-update" in <hibernate-mapping> for Employee and...


Caused by: net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)


michael wrote:
set cascade="save-update" or higher on your
association.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 4:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/74.html#A30


Top
 Profile  
 
 Post subject: Cool Docs!!!
PostPosted: Mon Apr 26, 2004 4:15 am 
Beginner
Beginner

Joined: Fri Apr 02, 2004 3:34 am
Posts: 40
Thanks!!!


michael wrote:


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