This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to persist data by using EntityManager.  RSS feed

 
xsunil kumar
Ranch Hand
Posts: 147
  • 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: 17309
11
IntelliJ IDE Mac Spring
  • 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: 147
  • 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
Boost this thread!