-->
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: EntityManager.merge() always appears to cause a SQL update.
PostPosted: Fri Sep 22, 2006 10:42 am 
Newbie

Joined: Thu Jun 01, 2006 11:31 am
Posts: 9
Hello,

Can you tell me what the merge() method looks at to decide whether an object needs to be updated.

In my application I'm seeing that *any* call to merge on one of my detached objects results in a SQL update call. Looking at the SQL call, it appears that every member of the object is being updated.

The pattern I see is as follows:

1. objects are instantiated (read in from the database) and held in a private collection
2. One of those objects is then 'merge()ed' - this is to ensure the object is not detached - this is necessary as it is very likely that the merge operation may be performed later in another thread.
3. Later at commit (or FlushtoDB() time), I see updates corresponding to the mappings defined in the annotations. (e.g. updates to the base tables, insert/delete operations to any join tables etc.).

The thing is, the application has not specifically updated any of these objects hence the reason for my question - what tells merge() that it needs to refresh the instance from the database?

-Thom


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really understand the question, can you provide a specific case/code and explain why you think this is not right?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:29 pm 
Newbie

Joined: Thu Jun 01, 2006 11:31 am
Posts: 9
Hello Emmanuel,

You misunderstand me - I'm not saying anything is broken!

What I'm seeking is an understanding off what steps the EntityManager performs to decide whether an entity should be updated following a merge request.

I have a situation here where I have some detached objects (that were fetched from a database) and I perform a merge on those objects. I'm noticing that everytime a merge call is made, an update of the database follows at commit time. I'm not explicitly changing the values of the objects in my application, but something must be as merge always creates some update statements following the merge call.

I strongly suspect that this is a bug in the application (not hibernate) but it would help a lot if you could briefly tell me what merge() looks at to decide whether an object needs updated in the database.

Thanks,

Thom


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate check each value type (property / association) of a given entity and apply an isEqual algorithm
If one of them is not equal, then the object is considered dirty.

you can check type.isEqual() or userType.isEqual()

In your case, that's probably a getter or a setter that mess stuffs around

_________________
Emmanuel


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.