• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to persist data by using EntityManager.

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic