-->
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: flush() not really save to database
PostPosted: Tue Feb 07, 2006 1:10 am 
Newbie

Joined: Tue Feb 07, 2006 12:29 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Version 2.1
Name and version of the database you are using:
Mysql 4.1.8
Code between sessionFactory.openSession() and session.close():

Adapter adapter = Adapter.getAdapter();
AuditLogInterceptor interceptor = new AuditLogInterceptor();
Session s = openHibernateSession(interceptor);
try {
interceptor.setSession(s);
interceptor.setUserId(ctx.getCallerPrincipal().getName());
interceptor.setTargetName(adapter.getAdapterId());

Set configs = adapter.getParams();
adapter.setParams(new HashSet());

// Save Adapter Object
s.save(adapter);
s.flush();

// Save Adapter Parameters
Iterator it = configs.iterator();
while (it.hasNext()) {
config = (AdapterParam) it.next();
config.setAdapter(adapter);
s.save(config);
}
s.flush();
}
catch (Exception e) {
throw new EJBException(e);
}
finally {
closeHibernateSession(s);
}

// In the Interceptor, the code is as following
public void postFlush(Iterator iterator) throws CallbackException {
try {
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306","user","password");
PreparedStatement ps = conn.prepareStatement("SELECT * FROM ADAPTER WHERE ADAPTER_ID = \'testPostFlush\'");
ResultSet rs = ps.executeQuery();

if (rs.next()) {
logger.info("ADAPTER \'testPostFlush\' EXISTS IN DB!!");
} else {
logger.info("ADAPTER \'testPostFlush\' DOES NOT EXIST IN DB!!");
}
} catch (Exception e) {
e.printStackTrace();
}
}

Full stack trace of any exception that occurs:
When I run my code, in the interceptor I get "ADAPTER 'testPostFlush' DOES NOT EXIST IN DB!!". I think it proves the data is not infact flushed to the database as it should be when I invoke the method "s.flush()". I am relying on the data to actually be flushed to the database immediately after invoking "s.flush()" for a function I wish to implement in the postFlush() method.

Anyone have same problem or any suggestions?
Is this a Hibernate 2.1 bug?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 2:26 am 
Newbie

Joined: Sun Oct 09, 2005 6:36 am
Posts: 19
Are you sure that using a new connection (==new transaction) in your interceptor is a good idea to test whether another transaction did write something to the database that it hasn't commited yet?


Top
 Profile  
 
 Post subject: similar problem
PostPosted: Tue Feb 07, 2006 11:12 pm 
Newbie

Joined: Tue Feb 07, 2006 7:15 pm
Posts: 2
I have a similar problem where I am unable to access a particular saved object, immediately after its creation (after the session.flush()).

This is for cache purposes in a multi server environment, after the creation of an object from one server the cache-reload on the other servers is invoked from the postFush() interceptor method on the original server.

Basically when the other servers try to load from the cache I get Hibernate exceptions saying that no such object exists in the DB.

I am also using Hibernate 2.1 (trying to migrate to 3.1 to see if that fixes the problem, but also having problems with migration... another thread...)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 9:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
have a search for something called 'transaction isolation'...


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.