• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

assertion error when unittesting persisting objects

 
Ranch Hand
Posts: 47
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help understanding why my test is failing.

I'm trying to unittest a persist method for persisting a user. The involwed classes are :

PersistenceManager (singleton for sharing a entitymanagerfactory app wide)

UserControler ( subclass of jpa entity User )

UserActions (junit testclass)

The problem I have is that when I get a entitymanager in the unittest and ask if it contain the just persisted user it returns false.

See below relevant code:

 
Ben Ooms
Ranch Hand
Posts: 47
Netbeans IDE Eclipse IDE Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,

I resolved the issue, my unittest is passing when i use the find instead of contains.



So that give us a new question:

Given the following scenario:
- jpa persistence with hibernate and H2 transactions configured "resource_local"
- Class A sharing a entityManagerFactory
- Class B getting a entityManager with class A factory and persisting an object Foo

if in a class C we get a entityManager with class A factory and query for Foo:
- contains return false
- find returns object foo as expected.

Can somebody explain what i'm missing to understand here?


 
And inside of my fortune cookie was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!