File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes problem in commiting the transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "problem in commiting the transaction" Watch "problem in commiting the transaction" New topic
Author

problem in commiting the transaction

Pankaj Chaudhary
Greenhorn

Joined: Jun 05, 2006
Posts: 16
hiii,
I make a small hibernate demo application with sapdb as backend.
In which i have sucessfull in retrieving from database.
But now i m inserting data in table.
and for that i m using session.save(objectname of bean)
and after that i have write transaction.commit()
but because of commiting the transaction a exception is thrown which
briefed below: Any help is appreciated:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NullPointerException
net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2253)
net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2018)
net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2007)
net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
net.sf.hibernate.examples.quickstart.ContactAction.execute(ContactAction.java:43)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

ok bye
any help is apprieciated
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

This is just my first guess. with the save method if there already exists an equal record in the database for that table, then save will through an exception. If you call saveOrUpdate, then Hibernate will check to see if it needs an insert or an update statement.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Pankaj Chaudhary
Greenhorn

Joined: Jun 05, 2006
Posts: 16
i have used saveorupdate it has problem "afterTransactionCompletion() was never called" message on server and no change in database
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
you are using hibernate 2.x (net.sf.hibernate packages).
can't you use hibernate 3.x (org.hibernate package structure) ?

anyway i'd sugest you create a testcase which is not based on struts (just a pure hibernate java app) and try to reproduce the problem.
this is a NullPointerException occuring inside hiberante, hard to tell why this happens whitout seeing some code...

cheers

pascal
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Can you post the code form when you create the Session to closing the session?

Thanks

Mark
Pankaj Chaudhary
Greenhorn

Joined: Jun 05, 2006
Posts: 16
hiii,
now i am using hibernate3 package.
now i have a exception on server like this

No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/apache-tomcat-5.5.12/webapps/quickstart/WEB-INF/lib/ehcache-0.7.jar!/ehcache-failsafe.xml

and when i used select query then data is retieved. but in case of inserting data no error is there but data doesnot save in table.

the code i writing is

Session session = HibernateUtil.currentSession();


Contact princess =new Contact();
Transaction tx = session.beginTransaction();
princess.setFirstName("Princess");
princess.setLastName("Elizabeth");
princess.setEmail("pri@yahoo.com");


session.saveOrUpdate(princess);


tx.commit();
session.close();

any suggestion......... plz
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Just as an FYI, now that you are using Hibernate 3.0 there is a new feature that would make your use of

Session session = HibernateUtil.currentSession();

not needed, as you can now ge the current Session from the SessionFactory. with SessionFactory.getCurrentSession(). Since everyone seemed to be using that Util class with a currentSession, Hibernate team now included that kind of functionality in the Factory.

Anyway, you basic code you have should work. Do you have an ID field? It might also end up being something in you config file. But now with Hibernate 3 and JDK 5.0 you can now use Annotations.

Mark

Mark
Pankaj Chaudhary
Greenhorn

Joined: Jun 05, 2006
Posts: 16
hiii,
i got the solution by flushing session before transaction commmited,but why this thing is needed plz tell if anyone knows.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

You shouldn't have to force a flush, unless you have changed the flushing settings in your configuration file.

You are closing the session in a finally statement and have a catch to catch excpetion and call transaction.rollback() right?

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in commiting the transaction