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: Object Identity Question
PostPosted: Sun Aug 02, 2009 3:58 pm 
Newbie

Joined: Sun Aug 02, 2009 3:43 pm
Posts: 2
In java persistence with hibernate, gavin suggests that we use business key for equality comparison. Business keys can not only involve multiple field comparisons, but there is no guarantee that the "perfect" business key's semantics will not change in future. We live in non ideal world and business requirements and laws change very frequently. In such case we will be left with data in db stored with multiple business key semantics.
I want to break problem into 2 parts
1. When we strictly deal with persistent or detached objects.
2. When we deal with transient objects.

1. I still don't see any downside on using a surrogate key for equality and hashcode if we are dealing with persistent and detached objects. 2 persistent objects or detached are equals if they same primary key . Is this wrong to assume ?

2. When we deal with transient objects, we can use the business key semantics to compare objects and have a merge strategy available if you try to persist 2 transient objects with same business key but different values in remainder attribute

In read heavy applications, where most of the transactions are read/update, this strategy should yeild a better performance. As, i am new to hibernate, any suggestions are appreciated.


Top
 Profile  
 
 Post subject: Re: Object Identity Question
PostPosted: Mon Aug 03, 2009 1:06 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
Standard solution at my place of employment is to enforce all business rules at the database.
That would mean either performing all modifying operations through a stored procedure rather than using raw SQL on the database (or hql or jpql of course), and/or using triggers that call the validation logic placed in stored procedures.
That way the database will always be consistent, even if the application(s) attempting to write to it are not doing correct validation themselves.
It also means that there is no code duplication, with multiple applications all having to implement the same validation routines. Rather, they defer validation to the database and handle any errors returned.


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.