This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in commiting the transaction

 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have used saveorupdate it has problem "afterTransactionCompletion() was never called" message on server and no change in database
 
pascal betz
Ranch Hand
Posts: 547
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code form when you create the Session to closing the session?

Thanks

Mark
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic