This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to persist data by using EntityManager.