-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to Detach Objects and load lazy collections
PostPosted: Thu Apr 08, 2004 5:33 pm 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
Hello,


I have an object of type A which is composed of an object of type B. Type B contains two collections, both of which are mapped with lazy load.

I have a mapper for A and a mapper for B, but there is a slight difference. When dealing with objects of type A, the information in B (including the collections) gets mapped to a different table than if B were mapped alone. So, when mapping A, the B component of A and its associated collections are mapped to table X.

Now, the mapper for B (i.e. if B is mapped by itself), puts the information in table Y.

Here's the problem:

I create an object of A:
openSession
session.save(a)
closeSession

then, I later pass the object of A over a queue which then extracts and saves B:
b = a.getB();
openSession
session.save(b)
closeSession

What happens here is that Hibernate deletes the collections from table X (which is mapped from A), and then inserts the collections into table Y (which is mapped from B). However, I want the data to be in both X and Y (i.e. do not delete from X).

This can be solved if I can completely detach A, filling in all lazy loaded data, etc. However, I don't see how this is possible with Hibernate.

Any help is appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 12:01 pm 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
Can anyone help in this question? If it is confusing, please let me know and I'll try to clarify it. This is a major problem for us with Hibernate.

Here's a more concrete example:

OrderRequest contains a Part and a Part contains a collection of Piece

We want all data in an OrderRequest (including all of the Part information) to be in a requests table. We then want to have a master Part table as well, but we don't want the data to be shared. So, the OrderRequest mapping file maps everything into one set of tables, and the Part mapping file maps everything into another set of tables (OrderRequest does not delegate the mapping of a Part to the Part mapping file).

Now, an OrderRequest comes in and we persist it. This works fine.

Later on, we decide we want to put the Part and its Piece collection into a master table. So, we extract the Part object from the OrderRequest and then call save on it. We want the data to be copied from the original OrderRequest Part object into the master tables. We don't want to delete the information from the OrderRequest tables. However, Hibernate decides to delete the collection from the OrderRequest tables and add it to the master tables.


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