Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Template not inserting data into the DB

 
Lisa Ray
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you commit your transaction?
 
Lisa Ray
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic