This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Not able to persist data by using EntityManager. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Not able to persist data by using EntityManager." Watch "Not able to persist data by using EntityManager." New topic
Author

Not able to persist data by using EntityManager.

xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
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.
 
GeeCON Prague 2014
 
subject: Not able to persist data by using EntityManager.