-->
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.  [ 8 posts ] 
Author Message
 Post subject: synchronizing two databases via application
PostPosted: Fri Nov 14, 2003 4:11 pm 
Newbie

Joined: Fri Nov 14, 2003 3:51 pm
Posts: 4
Hi,

What I am trying to do:

User logs into a webapp running on server A. Server A contacts server B via HTTP, asks to download some persistent objects. Server B load()s those objects using hibernate, and returns them to server A (as Java serialized objects). Server A then persists those objects to its own database.

When the objects are first created/saved (on Server B), they get generated UUIDs. When they get saved to Server A, they need to keep their IDs so they have the same primary key on both servers.

There are plenty of object relationships which need to be preserved by the download.

My question is, are there any obvious reasons why this shouldn't work?

My first attempts have been unsuccessful -- i think i'm getting bitten by cascades. I'll try disabling them and see if that helps; still, any advice is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 6:42 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do you use the exact same mapping ?
Having the server A mapping with assigned id might help (beware saveOrUpdate and assigned).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 6:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
HIbernate 2.1 offers the replicate() method for doing this stuff.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 1:10 pm 
Newbie

Joined: Fri Nov 14, 2003 3:51 pm
Posts: 4
gavin wrote:
HIbernate 2.1 offers the replicate() method for doing this stuff.


That looks like pretty much exactly what I want, but I'm having a problem with it.

I have a parent-child-type relationship mapped as a many-to-many using a List.

When I replicate() my top-level object, it puts rows for that object and all its children (recursively) into the database. So far, so good.

The problem is that it doesn't seem to be adding rows to the table which provides the many-to-many mapping.

It's clearly *finding* the reachable objects, since it's sticking them in the database. It just doesn't seem to be correctly replicating the association.

Is this intentional, or a bug, or do you think i'm doing something wrong?

-brian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sounds like a bug. This is brand new stuff. Submit a simple testcase to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 1:59 pm 
Newbie

Joined: Fri Nov 14, 2003 3:51 pm
Posts: 4
gavin wrote:
Sounds like a bug. This is brand new stuff. Submit a simple testcase to JIRA.


I have opened issue HB-479 for this problem.

-brian


Top
 Profile  
 
 Post subject: Re: synchronizing two databases via application
PostPosted: Tue Nov 18, 2003 2:32 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
bdenny wrote:
Hi,

What I am trying to do:

User logs into a webapp running on server A. Server A contacts server B via HTTP, asks to download some persistent objects. Server B load()s those objects using hibernate, and returns them to server A (as Java serialized objects). Server A then persists those objects to its own database.

When the objects are first created/saved (on Server B), they get generated UUIDs. When they get saved to Server A, they need to keep their IDs so they have the same primary key on both servers.

There are plenty of object relationships which need to be preserved by the download.

My question is, are there any obvious reasons why this shouldn't work?

My first attempts have been unsuccessful -- i think i'm getting bitten by cascades. I'll try disabling them and see if that helps; still, any advice is appreciated.


I have never used this way, but I think it must be more simple to send log file.
JDBC driver wrapper on sever A generates log file for updates with timestamps, server B connects, downloads, parses and executes sql.
Hibernate interceptor can help too, you can serialize objects in interceptor to log file, but I like text file more.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 10:27 am 
Newbie

Joined: Thu Sep 07, 2006 6:23 am
Posts: 1
bdenny wrote:
gavin wrote:
HIbernate 2.1 offers the replicate() method for doing this stuff.


That looks like pretty much exactly what I want, but I'm having a problem with it.

I have a parent-child-type relationship mapped as a many-to-many using a List.

When I replicate() my top-level object, it puts rows for that object and all its children (recursively) into the database. So far, so good.

The problem is that it doesn't seem to be adding rows to the table which provides the many-to-many mapping.

It's clearly *finding* the reachable objects, since it's sticking them in the database. It just doesn't seem to be correctly replicating the association.

Is this intentional, or a bug, or do you think i'm doing something wrong?

-brian


I have a problem with hibernate3.1 wihich looks quite similar.

I have a server running a oracle 10 database and many mobile clients using derby database, both using hibernate3.1 and the same database scheme (the same hibernate mapping file).

The mobile clients request objects (which are object trees) from the server database which were serialized and sent to the clients over network.

To persist the object tree on the client side I use Session.save on the root object since these object are new (transient) to the clients database.

Code:
Catalog catalog=(Catalog) objectInputStream.readObject();
....
session.save(catalog);


All data is persisted to the db, except for the association tables of the many-to-many associations which are empty. On java side the association consists of a SortedSet implemented by TreeSet.

When I create a new TreeSet on the client using the TreeSet of the deserialized object everything works fiine for the many-to-many association between Catalog and Chapters:

Code:
Catalog catalog=(Catalog) objectInputStream.readObject();
SortedSet set=new TreeSet( catalog.getChapters() );
catalog.setChapters ( set );
....
session.save( catalog);



In order to preserve primary keys all keys were generated by the application (generator="assigned").

Is this a hibernate bug or is it me doing something wrong here?


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