-->
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.  [ 6 posts ] 
Author Message
 Post subject: problems inserting data from another hibernate application
PostPosted: Sat Mar 24, 2007 6:50 pm 
Newbie

Joined: Sat Mar 24, 2007 6:41 pm
Posts: 3
Hi folks,
Having a bit of a problem inserting some rows to my database.

Basically, I'm sending some objects from another instance of an application via jms over to a master server. I need the master server to persist this data to its own db.

So I used uuid's for the id generation. And this works fine till I send the object over to the master server... when i call persist on the object it claims to have done it properly but no insert statements are issued. When I call merge, its does some selects but can't find the object, which is not surprising.

I feel like I'm missing something silly, and apologies if I am... but I can't see it at the moment.

Hope someone can help, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 1:49 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
I am doing something similar and ran into similar issues. Look at this:
http://www.hibernate.org/hib_docs/v3/re ... e-detached

Basically, you want to make sure that your master server is working with an object as a detached object.

If you are using Spring, it will handle the sessions appropriately, if used properly. This is how I am handling it. I don't know your full setup, but you are probably in another hibernate session and have to be careful with how you handle detached objects off the JMS queue.

Hope that helps!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 1:50 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
Replying to myself... my apologies...


If you state that 'merge' simply runs sql commands, then I believe it IS working. The merge is merging your detached object into the new session. I bet if you throw a 'flush()' after the merge, you'll see the update/insert statements.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 1:54 pm 
Newbie

Joined: Sat Mar 24, 2007 6:41 pm
Posts: 3
you're pretty much right.

The merge doesn't quite work first time through and it needs a saveOrUpdate then to get the detached entity into the db....

but essentially the problem I seem to have been having is use of different sessions for each thing (i'm actually working with seam and its a pain getting a hib session out of it when in a spring bean and no seam context).

but ta. you're helped!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 3:33 pm 
Newbie

Joined: Sat Mar 24, 2007 6:41 pm
Posts: 3
ok as an update to this....

as I'm assigning my uuid's manually like so:

Code:
private String id = IdGenerator.createId();


I'm finding that on rehydrating on the master server... a new id is getting generated. Any thoughts on how to bypass the new generation as its causing duplicates....?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 4:01 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
Well, you shouldn't generate the ID in the field declaration, I think. Was there an issue using hibernates UUID generator? (http://www.hibernate.org/hib_docs/v3/re ... on-id-uuid)
I'd also look into making the primary key a 'generated select' id. That way it won't create ids, just look for them after they are written to the table.

Also, ensure you have overridden your hash codes in all your objects.

A lot of these are shooting in the dark, as I don't know very many specifics of your application.


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