aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Template not inserting data into the DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Template not inserting data into the DB" Watch "Hibernate Template not inserting data into the DB" New topic
Author

Hibernate Template not inserting data into the DB

Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Hi All,
I'm unit testing a Hibernate app. The POJOs and mappings are in a JAR while placed in my app classpath. My Junit calls a Service which starts a new transaction to talk to the DAO in order to and perform any CRUD operations. The DAO is implemented using Spring Hibernate template. I'm taking care to inject a template into the DAO...there are no wiring exceptions at all.


My service can read data from the DAO. However, the problem is with insert.

Consider the code snippet taken from the DAO.


On the console I can see SELECT queries (called as a result of template.find() calls). But, I can't see any INSERT SQL statements when I call DAO.save method.
Any help shall be highly appreciated.

Thanks
Lisa
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Do you commit your transaction?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Do you commit your transaction

Why is there a need to commit the transaction explicitly?
I'm annotating the caller of the DAO with @Transaction; by default it used the REQUIRED transaction attribute.

Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
Try annotating the dao's save method with @Transactional (spring annotation), and if that in itself does not work, force it to create a new transaction by annotating it with @Transactional (propagation = Propagation.REQUIRES_NEW).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Template not inserting data into the DB