• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Spring,JUnit, Hibernate and persistence db but not insert

 
Greenhorn
Posts: 11
Eclipse IDE Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my spring-master.xml

my spring-datasource.xml

and my spring-hibernate.xml

My Dao Class and Imp :



I want to probe this by Junit like this:

Run this by Junit test and take this:

The database is create but the data id-generated,ayambo,toledo not inserted, the database is Postgresql 9.0.3, please?, What i do wrong???
Pdta: I now that hibernatetemplate is unused, but the configuration is ok??(Sorry for my bad english.)
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using Spring in your unit test and transactions. The default behavior of transactions on test methods is to rollback any changes at the end of the test method. Based on your log at the end, it shows that Hibernate is running the insert and the select. But is your test failing?

Also, in your component-scan, you are excluding classes that are annotated with @Repository??? Or are they getting picked up by your second component-scan?

Also, be know, if you are using a version of Hibernate that is higher than 3.1, then you are gaining nothing by using the HibernateTemplate, and would be better of injecting the SessionFactory into your DAO and using straight Hibernate code.

So your code would then look like


You will still get HibernateExceptions translated to Spring's DataAccessException hierarchy with @Repository and your bean for the
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

Mark

Mark
 
Ricardo Llontop
Greenhorn
Posts: 11
Eclipse IDE Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark for reply, the only that I fail is that Junit roolback default true, I change this:
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false).

Thnks.

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricardo Llontop wrote:Thanks Mark for reply, the only that I fail is that Junit roolback default true, I change this:
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false).

Thnks.



Yep, so now with that setting all the transactions will commit.

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic