File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring,JUnit, Hibernate and persistence db but not insert

 
Ricardo Llontop
Greenhorn
Posts: 11
Eclipse IDE Linux Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • 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.)
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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 Linux Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic