This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes assertion error when unittesting persisting objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "assertion error when unittesting persisting objects" Watch "assertion error when unittesting persisting objects" New topic
Author

assertion error when unittesting persisting objects

Ben Ooms
Ranch Hand

Joined: May 16, 2011
Posts: 44

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

Joined: May 16, 2011
Posts: 44

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?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assertion error when unittesting persisting objects