-->
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.  [ 1 post ] 
Author Message
 Post subject: Globally unique object
PostPosted: Wed Jan 16, 2008 7:02 am 
Newbie

Joined: Wed Jan 16, 2008 5:39 am
Posts: 1
I have a Hibernate question about globally unique objects. It is not related to a specific Hibernate version, but for completeness: I'm using version 3.2.0.ga.

The question is this: How do I create and manage objects that are unique across more than one database?

I will give an example of what I mean:

I have a Project object that links to a Template object (many-to-one). All projects I create must use the same Template object and this goes for all databases in which I create my Project objects. Also, if I move a Project from one database to another I want it to point to a Template object with the same ID and data as it did in the database it came from.

To solve this I created a static Template field with a fixed identifier in my code. But if I try to use that with Hibernate I get 'duplicate object found' messages because sometimes there is more than one Template object with the same key in memory: when a new project is created with the static constant and an old project was read from the database (along with its Template). In that case both Template objects in memory have the same identifier and field values, but they are not phisically the same object in the JVM.

Currently my workaround is to manually replace any new references to the static constant with a reference to the Template object already in the database just before saving a new Project, but obviously this is not what I want...

Does anyone have any ideas on how to correctly solve my problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.