This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA JSE and JUnit

 
Markus Schmider
Ranch Hand
Posts: 132
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
@Before
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
Posts: 132
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic