-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using Hibernate to replicate Databases
PostPosted: Mon Dec 18, 2006 1:04 pm 
Newbie

Joined: Mon Apr 17, 2006 6:18 pm
Posts: 12
Hi,

I'm writing a distributed application using hibernate. Because all parts of the application should be able to work offline, every part has an own database.

Now I'm writing a framework to distribute data to all parts of the application. My idea is to send hibernate-mapping-objects between the parts and just to commit the actions at the destination.

For this case I have to avoid generated primary-key ids. Can you think of any other restrictions? What do you think at all about the idea?

Best regards Michael


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 3:15 pm 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
Using hibernate for mass insertions is SLOOOOOOOW!

You also have to deal with concurrency issues.
For example:

Table A:
- id (number)
- whatever else

Table B:
- id (number)
- aReference (references id of A)

Now if you read in all of table A and blast it over to another database, then do all of table B, you have a problem: What happens if a transaction inserts a record pair (A and B) along the way?
You've already read table A, so you don't have the A reference, but when you copy over table B, the foreign key will expect the record in A! Oops!


Most real databases have replication tools available which deal with this issue and more. They're also much faster than reading/writing records in a Java application. Use the right tool for the job.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 4:15 am 
Newbie

Joined: Mon Apr 17, 2006 6:18 pm
Posts: 12
OK, I think I didnt choose my words wisely. I dont want to replicate the database, I want to synchronize some data. There are only some data, that have to be synchronized, so its not enough to do a whole replication.

One possibility was to define my own object to store all the data of the hibernate object, send this own defined object to the other application, build the new hibernate object and do an update by this object.

Or I could just serialize the hibernate object as it is, send this to the remote application and do the update by this object.

The second possibility would be much less work. But I can imagine, that there are some tricky things to regard (like not using hibernate generated keys).

So should I do the extra work and define some new classes to send objects over the network or can I send the hibernate objects?

Best regards Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 1:05 pm 
Regular
Regular

Joined: Tue Jun 08, 2004 8:24 am
Posts: 57
You'll want to be careful serializing beans obtained through Hibernate, as they also contain Hibernate specific info.

One idea would be to make your POJOs serializable, then use http://jakarta.apache.org/commons/beanutils/ to copy the properties (Using BeanUtils.CopyProperties http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/BeanUtils.html#copyProperties(java.lang.Object,%20java.lang.Object)) from the hibernate bean to your fresh bean before serializing it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 2:55 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
MichaelBulla wrote:
Or I could just serialize the hibernate object as it is, send this to the remote application and do the update by this object.

The second possibility would be much less work. But I can imagine, that there are some tricky things to regard (like not using hibernate generated keys).

So should I do the extra work and define some new classes to send objects over the network or can I send the hibernate objects?

Well, I already wrote an app using RMI and sending objects created by Hibernate to the client. The only problem I ever encountered was the lazy-loading: obviously, you will have to take care about not trying to use lazy-loaded properties on the other side.

Apart from this, I don't think there's a something special to watch out about sending your H3 POJOS. Just make them serializable, send them and read them (and rule them all :-p).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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