Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Spring,JUnit, Hibernate and persistence db but not insert

 
Greenhorn
Posts: 11
Eclipse IDE Postgres Database Linux
  • 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.)
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • 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 Postgres Database Linux
  • 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
Posts: 17344
11
Mac IntelliJ IDE Spring
  • 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 wasn't selected to go to mars. This tiny ad got in ahead of me:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!