Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate Template not inserting data into the DB

 
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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.

 
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).
 
    Bookmark Topic Watch Topic
  • New Topic