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.  [ 3 posts ] 
Author Message
 Post subject: How solve equals/set problem for table with no business key?
PostPosted: Wed Mar 22, 2006 7:49 pm 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Dear members,

I have a table (Movement) defined with no business key, so I have as primary key an autoincrement integer number. The problem comes because a shareholder makes a set of movements, so I need a relation between shareholder an movement. Tipically implemented as set.

Becuase the key is generated if I want to add new movements on the shareholder, I always add only one element, because Hibernate assign the key (generated) after the movement is saved.

Do you have any idea about how to solve this problem. I don't have any real business key in order to implement an intelligent equals/hashcode. I was thinking to add a new field for example creation time in order to really have different element after new Movement(). Do you think it is a good solution for that?

The solution saving before inserting the new element on the set doesn't look efficient.

Do you have any idea about how to solve this problem?

Thanks in advance,

David

P.S.: I was reading the Wiki about equals/hashcode but it doesn't help for this situation.

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 11:36 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Are you sure that there's no business key? How about this: if a Shareholder can make only one Movement at a time, you have your business key: Shareholder + Movement datetime.

If you absolutely, positively cannot come up with a business key, your options include (and are not limited to):

1) Change the generator to assigned, and use the primary key as the business key (icky, but as this is a lifecycle-dependent child object, less icky than it usually would be).

2) Change the set to a list, and use the list index as the business key. This one has the advantage that the list index has proper business meaning: this Movement is this Shareholders 73rd transaction, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 8:41 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Dear tenwit,

So the solution is in some way is to invent a kind of business key as I guess or to just use a list. I have some suspect about this second solution, because in general the set is the best way to have unique elements.

Thanks for your help, now I am sure about my intuition about how to solve this problem, I just want to verify how this problem was solved by other members.

Thanks,

David

_________________
David Leal


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