-->
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.  [ 6 posts ] 
Author Message
 Post subject: Unexpected updates when selecting a parent with a collection
PostPosted: Tue Dec 11, 2007 7:34 am 
Newbie

Joined: Mon Dec 10, 2007 10:21 am
Posts: 4
Hi,

I am getting unexpected Update statements when doing simple selects.

It only occurs on one-to-many relationships.

For example, I do a hibernateTemplate.get(class, id) on the parent object. When the session commits, I notice a whole bunch of update statements being run on the children.

It happens on all of our parent-children classes.

Obviously something is getting changed and Hibernate is rightly detecting it, then doing the update. But I can't figure out what is making the change.

Doing a direct get/select on the child does not cause updates, so I don't think it's a problem with the getters/setters on the individual class.

The mapping looks like:

Code:

private List<SkuOptionDO> skuOptionList = new ArrayList<SkuOptionDO>();

       @OneToMany(mappedBy = "skuType", cascade={CascadeType.ALL})
   public List<SkuOptionDO> getSkuOptionList() {
      return skuOptionList;
   }
   public void setSkuOptionList(List<SkuOptionDO> skuOptionList) {
      this.skuOptionList = skuOptionList;
   }




Any ideas what could be causing the updates on the collection?

Thanks.


Hibermate 3.2.0
Java 1.5.0_11
MySQL 5.0


Top
 Profile  
 
 Post subject: Part Two
PostPosted: Tue Dec 11, 2007 11:39 am 
Newbie

Joined: Mon Dec 10, 2007 10:21 am
Posts: 4
I am now part way to solving the mystery.

We have a class that extends DefaultSaveOrUpdateEventListener, that overrides public void onSaveOrUpdate(SaveOrUpdateEvent event).

The method is supposed to be called whenever a Save or Update is about to happen and set the audit fields (created and updated timestamps).

For some reason, this method is getting called when the session/transaction commits on a hibernateTemplate.get(class, id).

Of course, then the timestamps are changed at it has to do an update.

If I take the listener out of the config, no update SQL shows up.



So the new question is:

Why is the DefaultSaveOrUpdateEventListener.onSaveOrUpdate(SaveOrUpdateEvent event) method being called when the session commits at the end of a hibernateTemplate.get(class, id) call?

And why does it only happen on objects in a collection?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 12, 2007 2:05 am 
Newbie

Joined: Thu Jun 28, 2007 7:30 pm
Posts: 7
Oddly enough, I ran into the exact same problem today. I fixed it by changing Session.FlushMode from Auto to Commit. I have already made sure I do database modifications in a transaction, and explicitly call Commit when I am done.

I think it is when you lazy load a collection. The version is changed after the collection is populated, although it probably shouldn't be.


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Feb 13, 2008 3:50 am 
Newbie

Joined: Wed Jan 23, 2008 7:45 am
Posts: 14
Location: Pune,India
Hello
I am facing the same problem and unfortunately I don't think that setting the Session FlushMode as COMMIT is a good solution. Our Sessions are returned from a SessionFactory managed via Spring. Each DAO class gets a current Session Obj for itself and fires queries. The Session FlushMode is AUTO by default and hence there is no need to call a commit.

Does anybody have a better solution?

_________________
Harshal Vaidya


Top
 Profile  
 
 Post subject: I found out a solution.
PostPosted: Mon Feb 18, 2008 9:43 am 
Newbie

Joined: Wed Jan 23, 2008 7:45 am
Posts: 14
Location: Pune,India
I finally found a temporary workaround.

Before your select query fires do a

Code:
org.Hibernate.Query query = createYourQuery();
query.setReadOnly(true);


Thats does it.

_________________
Harshal Vaidya


Top
 Profile  
 
 Post subject: unexpected updates when selecting
PostPosted: Mon Feb 18, 2008 11:56 am 
Newbie

Joined: Sat Jan 19, 2008 2:28 pm
Posts: 1
Location: Germany
I have the same problem with annotations and entityManager. But only when I use a EntityTransaction. When I commit the EntityTransaction I get these updates. When I don't use EntityTransactions everything works fine!?!?


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