This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to persist data by using EntityManager.

 
xsunil kumar
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am trying to persist data in database using JPA and spring services. I have written one service class and i am trying to do by using junit test class.

But i am not able to persist data in database. I am able to fetch data from database.

Below are the code.



Please help me where i am wrong.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing true Spring injecting in your tests with @RunsWith and @ContextConfig on top of your BaseServiceTestCase? Isn't it transactional where at the end of the test the data gets rolled back?

Also, if this is a unit test of a service class, why aren't you stubbing or mocking out the Repository (Database access).

The service class does not access the database and shouldn't. That would be tightly coupling business logic with database calls.

Mark
 
xsunil kumar
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My base test class is



I have tried by removing @Transactional also, but still i am not able to persist. I am able to pull data by using emf. find method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic