-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate saves an empty object when fetching an other
PostPosted: Mon Mar 10, 2008 8:17 pm 
Newbie

Joined: Mon Mar 10, 2008 8:03 pm
Posts: 2
Hibernate version:
3

Situation:
I have 3 classes that are linked 1 that holds a collection of objects of type 2 and type 2 holds 1 of type 3

When i save 1 all the others get saved as well (all good there), cascade is set to save-update as it should.

The problems start when i try to fetch an object of typ 1. Hibernate gets that object without a problem and the objects of type 2 in the set aswell. BUT not the type 3 object that's in the type 2 object. What he does is when he fetches the type 2 object is make a new empty type 3 object and for some reason saves that one, instead of getting the actual object from the database.

I'm using the latest version of MySQL

Mapping:
type 1:
<set name="type2s" cascade="save-update" where="bla='foo'">
<key column="type1Id"/>
<one-to-many class="Type2"/>
</set>

type 2:
<many-to-one name="type3" column="type3Id" cascade="save-update"/>

type 3:
no relevant mapping


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 10:06 am 
Newbie

Joined: Tue Mar 11, 2008 9:22 am
Posts: 3
Hibernate will be using Lazy Loading to fetch your Type3 entity. This will be a proxy to the entity in the database.

Do you really want to update the Type3 object when you save the Type1 entity? To me it looks as if the Type2 object is a link table in a many-to-many mapping with a reference to some form of lookup table, is this correct?

Is Hibernate actually creating empty records in the table which holds the Type3 entities>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 11:29 am 
Newbie

Joined: Mon Mar 10, 2008 8:03 pm
Posts: 2
yea it was making new objects and updating the references

i found out that it was cuz i encapsulated all my objects so that when i put a object of type 2 in type one 1 i created a new instance.

when i removed this it all worked fine but i still think it should of worked before aswell


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