-->
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.  [ 4 posts ] 
Author Message
 Post subject: ignore certain properties during merge
PostPosted: Fri Jun 27, 2008 10:53 pm 
Newbie

Joined: Tue Sep 26, 2006 11:54 am
Posts: 10
Hi,

I have this problem to solve where I have an entity that has these mapped properties (note that this is a really simplified version of my entity):

Code:
RequestEntity
  boolean isOverridden
  String otherField


In thread 1, when a new RequestEntity is created and inserted in the table, it also executes a JPQL UPDATE statement that sets the isOverridden property of other existing RequestEntity rows in the table.

In thread 2 (or another process), the RequestEntity instances are used and updated as well. This other thread does not care about the isOverridden property at all, but it must eventually save new values in the otherField property.

If both thread run at the same time, I have situations where the second thread overrides the isOverriden value that thread 1 updated with the one that it loaded before the update (which is different).

What is the best solution to this kind of problem? Both threads should be able to live together without waiting on each other to finish its job (i.e., there should be no lock and no stale exception should occur).

Ideally, the thread 2 should just save the RequestEntity without setting the isOverridden field, but that only seems possible if the update in thread 2 uses a JPQL UPDATE query that does not modify that property.

Is this a classical problem that has a classical solution?

--
Mel T


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 28, 2008 10:02 pm 
Newbie

Joined: Tue Sep 26, 2006 11:54 am
Posts: 10
I tried this solution:

I added another entity class which is a subset of the initial RequestEntity. I now have:

Code:
RequestEntity
  String id
  boolean isOverridden
  String otherField

OverridableRequestEntity
  String id
  boolean isOverridden

I changed the mapping definition of the RequestEntity, specifying that isOverridden is not updatable.

The mapping for the OverridableRequestEntity is a reduced version of the RequestEntity mapping, with the isOverriddenBy property updatable. Both refer to the same DB table.

When inserting RequestEntity instances, I update the OverridableRequestEntity objects using the adapted JPQL update query.

This solves my problem. An opinion on this pattern would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:29 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If the property is called isOverridden, do you then have a method called isisOverridden? Shouldn't the property be called overridden?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 2:55 pm 
Newbie

Joined: Tue Sep 26, 2006 11:54 am
Posts: 10
Cameron McKenzie wrote:
If the property is called isOverridden, do you then have a method called isisOverridden? Shouldn't the property be called overridden?


Of course. But my example was not actual code, but just provided to illustrate the issue.


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