wood burning stoves*
The moose likes Object Relational Mapping and the fly likes Problem with Hibernate database Session with flush() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with Hibernate database Session with flush() ?" Watch "Problem with Hibernate database Session with flush() ?" New topic
Author

Problem with Hibernate database Session with flush() ?

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi,
I am facing problem while calling method

1) DB.flush();

2) public static void flush() {
LOG.debug(".... Flush ....");
HibernateUtil.getSession().flush();
}

3)

public static Session getSession()
throws InfrastructureException {
Session s = threadSession.get();
try {
if (s == null) {
LOG.debug("Opening new Session for this thread.");
if (getInterceptor() != null) {
LOG.info("Using interceptor: " + getInterceptor().getClass());
s = getSessionFactory().openSession(getInterceptor());
} else {
LOG.debug("No intereptor");
s = getSessionFactory().openSession();
LOG.debug("Got session");
}
threadSession.set(s);
LOG.debug("Put session in threadsession");
}
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}

// never auto flush
s.setFlushMode(FlushMode.MANUAL);

return s;
}

After wards i am getting error like :

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
and

2009-08-07 10:58:19,005 ERROR http-8084-Processor25 event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

could you have any clue to resolve this issue.

Regards,
xyz
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Are you getting the exception in all three cases or .. ?

And I don't understand the below code ?


And please use code tags when posting code.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
No i am getting 1 exception , when the Db.flush() method finishes the call...and i have shown the three methods which using in call...

and theradSession is : instance of ThreadLocal..

private static final ThreadLocal<Session> threadSession = new ThreadLocal<Session>();
 
Consider Paul's rocket mass heater.
 
subject: Problem with Hibernate database Session with flush() ?
 
Similar Threads
[Hibernate] NoClassDefFoundError
Through Hibernate,Struts2,Spring integration, While save records in MySQL table it's always updating
Help with JPA/Hibernate + MsSqlServer
hibernate session: to close or not to close
Caching Issues with Hibnernate