-->
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.  [ 2 posts ] 
Author Message
 Post subject: composite problem
PostPosted: Thu Apr 29, 2004 11:51 am 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 7
Hi,

my problem is that I do not how/where to start with hibernate
and the following setup:

We have a mysql legacy database. In it there are some tables
that have a composite key.

for instance:

myID : unsigned integer, not null, auto_increment
appoved: boolean, not null
data: varchar(200)
someMoreData: varchar(100)
...

the primary key is actually (myID, approved).

The setup is a follows:
data is submitted or updated and comes in a approved=false state
record. All the while the data in the approved=true record (on an
update) is still the same.

Then another user reviews the data and approves it, upon which
the object is again persisted into the approved=false state and
also updated (or inserted) in the approved=true record.

My question is actually:
how to map such a construction? Are there some interfaces to
implement on the pojo's? specific classes? methods?

And for the persisting ... how to do it easily if it can be done at all?

It is a demand that at any one time, there is only 0,1,2 records
with a certain myID inside the table.

kind regards,
Dimitri Smits
aka gongo


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 6:23 pm 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
There are several ways that will work. The first doesn't really address your question but might be a better solution: add a new column for the primary key and convert the existing PK into a unique key. That's what I'd do in this case as it's generally better to keep business meaning out of the PKs.

The other 2 approaches are:
1. Use a <composite-id> for this mapping. Easy to do, see the ref docs. Note you MUST implement equals() and hashCode() for your composite ID class (jakarta commons lang Builder classes make this easy).

2. If you don't need to access these on their own, but rather they are always accessed via some other object (e.g, the child side of a parent-child relationship), then you can use a component mapping. Dependent components have a compound pk of their <key> and <index> columns.


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