-->
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: Commit unexpected behaviour
PostPosted: Fri Jun 04, 2004 9:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi guys,

release 2.1.2
DB oracle 8i

(simplified) Domain Model
A many-to-one B (non bidirectionnal + cascade = all)

use case:
0- //beginTransation
1- creating new B instance
2- session.save(b); // sequence is hit --> ok
3- session.find ("from A a where a.aId = 123); // flush is triggered, insert of new b is executed --> ok
4- a.setB(b) // nothing in log --> normal no flush is needed here
5- session.commit() // nothing is happening, the commit is done since i can see the row of the previous insert in the DB, but i expect a new flush to be done just before the commit since b has been updated

if i manually add session.flush() just before commit, all works fine

i was just wondering if i misunderstood the fact that a flush was done automatically before a commit when flushMode= auto

Thx

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 05, 2004 8:18 am 
Beginner
Beginner

Joined: Thu May 13, 2004 5:51 am
Posts: 28
umm .. shouldnt A instance be updated/saved ?
session.saveOrUpdate(a) ????

As I understand, with above and the object graph that you have, B will be updated too when commit happens. There will then be a flush at tx.commit.

--


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 05, 2004 11:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i don't have to saveOrUpdate A since it has been loaded in the current session.... i really don't know why my current session did not notice A modifications

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 05, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Most likely you have your FlushMode set to NEVER, in which case a flush never happens until you explicitly call it aside from some special cases like queries against tables with changes waiting to be flushed. That would certainly explain the behaviour you are seeing.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 05, 2004 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
flushmode is auto since in step 3 i can see the sql insert generated just before the select (find method)
I'll check all this on monday

thanks for the tip

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Commit unexpected behaviour (no flush in commit why)
PostPosted: Thu Jun 05, 2008 12:34 am 
Newbie

Joined: Thu Jun 05, 2008 12:11 am
Posts: 1
Location: Islamabad, Pakistan
Hi All,

I am a J2EE Developer.

I am using JDBC Transaction not JTA. Also using JBoss, but doesn't matter as in standalone i think behavior is same.

By default Session flush mode is auto, it means at any query execution and at transaction.commit(); it should work.

Flush is not working in 3 of the four ways.

1. Not worked, Default auto flush.

2.Not worked, Session session = sessionFactory.openSession();
session.setFlushMode(FlushMode.COMMIT);

3.Not worked, Set the property in hibernate.cfg.xml <property name="hibernate.transaction.flush_before_completion">true</property>

4. Worked ,
session.flush();
tx.commit();

Why the first three are not working, as according to hibernate doc all should work.

My code is as follows,

public void mySave(MyDTO dto) throws Exception {

Session session = null;
Transaction tx = null;
try {
session = hibernate.openSession();
tx = session.beginTransaction();

session.save(dto);
/////////////////
//session.flush(); // I f i remove/comment this line then problem occurs
//////////////////
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
throw new BSException(e);
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
}
finally {
if (session != null) {
session.close();
}
}
}

output is much like

Hibernate: Select max(id) from mytable;

=================End of output.

In 4th case when I do session.flush b4 tx.commit() manually; then output is much like, and it works fine
Hibernate: Select max(id) from mytable;
Hibernate: insert into mytable(a, b) values (?, ?);


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.