File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes JPA JSE and JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA JSE and JUnit " Watch "JPA JSE and JUnit " New topic

JPA JSE and JUnit

Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 116
Hello I have a JSE (desktop) application which uses JPA.
When I try to JUnit Test it, I run into a strange problem.
Basically I have two Entities which extend a superclass.

I need to test that the attribute nr is unique for each subclass, but that same values are allowed between subclasses.
I think this works, but my JUnit test behaves strangely:

When run each test in isolation, the tests pass. But when I run the whole class, testUniqueNr() is executed and then the RollbackException somehow causes
public void cleanUp()
not to be executed and the testSelbeNrInVerschiedenenSchluessellisten() fails.
When I (expected=RollbackException.class) and use a try catch block I get the same behavior.

Many thanks for any input

from my pom.xml:
Markus Schmider
Ranch Hand

Joined: Feb 25, 2007
Posts: 116
I have to correct myself slightly. The debugging with the failed test indication had confused me.
After the execution of

is executed, but there a ConstraintViolation exception is thrown while I try to delete the entities.:
javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: ORA-00001: unique constraint (TEST.SYS_C0013343) violated

So the problem occurs when I run cleanUp after testUniqueNr where the exeption is excpected.

relevant code:
I agree. Here's the link:
subject: JPA JSE and JUnit
It's not a secret anymore!