-->
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: Two Hibernate DBs with Same Schema, Copying from A to B
PostPosted: Wed May 14, 2008 6:31 pm 
Newbie

Joined: Wed May 14, 2008 6:13 pm
Posts: 8
I have a general question about the best approach for copying data between two databases managed by Hibernate. I have as of yet have not found a set of best practices for his.

We are using:
* Eclipse RCP 3.3
* Java 1.5
* Hibernate 3
* HSQL 1.8

Basically, we are deploying a desktop application to our customers. We have a need to be able to import from one application's database (A) to the user's application database (B).

The issues I have:
1. Configure HSQL to support two databases (outside of scope on this forum)
2. Configure Hibernate to talk to both databases simultaneously
3. Copy an object from database A to database B

As for issue 2, I believe it is a simple matter of multiple session factories, one for each database. I then have DAOs use the correction session factory.

As for issue 3, do I need to do a deep copy? Or there other means of taking an object from DB A, sanitizing it and then creating a new instances in DB B?[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 11:06 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
As for issue 2, I believe it is a simple matter of multiple session factories, one for each database. I then have DAOs use the correction session factory.


Yes, this is indeed correct. Just create multiple session factories with individualized hibernate_dbx.cfg.xml files, and make sure the DAOs are associated with the appropriate session factory. A bit of work, but not too much.

Quote:
As for issue 3, do I need to do a deep copy? Or there other means of taking an object from DB A, sanitizing it and then creating a new instances in DB B?


Indeed, a deep copy will be needed to ensure you don't lose any data.

You can always entertain Hibernate Shards as well.

Good luck!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 8:50 am 
Newbie

Joined: Wed May 14, 2008 6:13 pm
Posts: 8
Cameron McKenzie wrote:
Yes, this is indeed correct. Just create multiple session factories with individualized hibernate_dbx.cfg.xml files, and make sure the DAOs are associated with the appropriate session factory. A bit of work, but not too much.


Thanks. It is good to know we are headed in the right direction.

Cameron McKenzie wrote:
Indeed, a deep copy will be needed to ensure you don't lose any data.


I am curious. Is it possible to re-use objects by resetting the object id to null and handing to a different session factory session? I hope yes; however, given that we have proxy objects associated with another session factory session that doing so may cause hiccups. Thoughts? Experiences?


Top
 Profile  
 
 Post subject: Re: Two Hibernate DBs with Same Schema, Copying from A to B
PostPosted: Thu Mar 07, 2013 10:01 am 
Newbie

Joined: Thu Mar 07, 2013 9:59 am
Posts: 1
I believe you can use this:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#objectstate-replicating


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.