-->
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: Problem with FLUSH_MODE and rolling back.
PostPosted: Fri Jun 08, 2007 6:53 pm 
Newbie

Joined: Sun Jan 29, 2006 9:27 pm
Posts: 10
Hibernate version: 3.2.4.sp1
Mapping documents: Annotations 3.3.0.GA

Code:
@Entity
@Table(name = "t_mmx_role")
@Proxy(lazy = false)
public class MRole extends MBase { // MBase has the id
  private String name;
  private String description;

  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
  public String getDescription() { return description; }
  public void setDescription(String description) { this.description = description; }
}


Code between sessionFactory.openSession() and session.close():
Code:
Session session = sessionFactory.openSession();
// Flush only at commit, don't flush at queries (or any other time)
session.setFlushMode(FlushMode.COMMIT);
session.beginTransaction();

MRole r = new MRole();
r.setName("something");

// This is making a flush (and should not)
session.saveOrUpdate(r);

// Not making rollback of the r created object
session.getTransaction().rollback();
session.close();


Name and version of the database you are using:

Tested in:
mysql-max-4.1.12-pc-linux-gnu-i686
mysql-standard-5.0.19-linux-i686
mysql-5.0.37-linux-i686-glibc23

The problem:

This used to work. We worked this way for at least a year. The problem is that the saveOrUpdate is flushing to the database, this is bad, but it's worst that the rollback is not working.

In other words, if I put a breakpoint in the saveOrUpdate line and make a select to the role table there is no role in the DB, step over saveOrUpdate and there is a record in the DB. Step over rollback and the record remains there.

We have a well defined and proved standard way of working with hibernate which gave us no problems, but since a few versions, we are having wierd problems and we believe that this transaction problem can be the root cause.

Any help is appreciated it.

Regards Demián.


Top
 Profile  
 
 Post subject: Exact Same Issue
PostPosted: Thu Jun 14, 2007 6:51 pm 
Newbie

Joined: Wed May 05, 2004 12:22 am
Posts: 5
I am having this exact same issue....

A couple of differences:

1. This isn't just a session.saveOrUpdate() issue with me, my object will persist even if I just do a session.load() another object or do a regular session.update();

2. I found someone who suggested setting the FlushMode.COMMIT after you beginTransaction(), however that didn't seem to help.

3. I am 100% certain I am not calling flush() myself.

4. This isn't a random thing, where hibernate decides its time to flush. It happens every time I run the code, which looks almost exactly like yours.

Someone must know what we are doing wrong...


Top
 Profile  
 
 Post subject: Re: Exact Same Issue
PostPosted: Mon Jun 18, 2007 10:42 am 
Newbie

Joined: Sun Jan 29, 2006 9:27 pm
Posts: 10
Apoptosis66 wrote:
1. This isn't just a session.saveOrUpdate() issue with me, my object will persist even if I just do a session.load() another object or do a regular session.update();


Well, I have not tested all, but it's possible (and logic) to think that it happens (makes flush) also on update, load, query.list, query.iterate and probably others, depending of the flush mode, hibernate makes or not a flush prior to make a query (like in a load).

Apoptosis66 wrote:
2. I found someone who suggested setting the FlushMode.COMMIT after you beginTransaction(), however that didn't seem to help.


Yes, that is (or was) the solution. In fact we always handled it with FlushMode.COMMIT and it used to behave right. We just don't know why it's not working now.

Apoptosis66 wrote:
Someone must know what we are doing wrong...


Well... it worked well for at least a year and a half, so I don't think we are doing something really wrong. Maybe someone changed the way that feature works, or there is a bug in the framework (or we are not understanding how to use the feature, but as I told you it has been working for at least one year and a half).

In any case, it would be nice to hear an official opinion from the hibernate team.


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.