-->
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: To copy persistent object from a database to the other.
PostPosted: Tue May 24, 2005 12:46 am 
Newbie

Joined: Tue May 24, 2005 12:28 am
Posts: 3
Hi,

Does anyone have good idea to copy persistent object between two databases? My scenario is:

1) Retrieve object from databse A by such as session.load() or query.

2) Serialize persistent object into byte stream by ObjectOutputStream.

3) Send chunk of bytes to another machine thru network.

4) Deserialize it by ObjectInputStream into persistent object.

5) Save persistent object to database B.

However, at step 5), how can I save the object into other database than original? The object has it's own id and I've tried to clear it to make database B assign new id. But hibernate says 'could not initialize proxy'. Is ther way to retrieve pojo DMO from proxy so that I can save it into database B?

Hibernate version:3.0.3

_________________
---
Ruimo


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 1:57 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Maybe this link helps: http://forum.hibernate.org/viewtopic.ph ... highlight=


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 2:15 am 
Newbie

Joined: Tue May 24, 2005 12:28 am
Posts: 3
Thanks! Your information really helps. I can get implementation object by following code.

Object o = ((HibernateProxy)obj).getHibernateLazyInitializer().getImplementation();

_________________
---
Ruimo


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 5:00 am 
Newbie

Joined: Tue May 24, 2005 12:28 am
Posts: 3
ruimo wrote:
Thanks! Your information really helps. I can get implementation object by following code.

Object o = ((HibernateProxy)obj).getHibernateLazyInitializer().getImplementation();


I noticed that if the persistent object has association such as List, its type is org.hibernate.collection.PersistentList.

Code:
public class Entity {
    private List items = new ArrayList();


If I save this object into other database by Session.save(), the association seems to be ignored and not saved. I can avoid this issue to make new ArrayList object before saving this entity.

Code:
    items = new Arraylist(items);


However, this seems a bit dirty trick to me. Does anyone know smarter way?

_________________
---
Ruimo


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.