This discussion is archived
1 Reply Latest reply: Apr 2, 2012 8:52 AM by cdelahun RSS

Unit Test code using wrong persistence unit

513108 Newbie
Currently Being Moderated
In the midst of learning Maven, I created a simple application in which I am using JPA (Java Persistence 1.0.2) with EclipseLink implementation (2.0.2).

Note: This is an Application Managed environment. So I manually control EntityManager's life cycle.

The persistence.xml file used by the main source code is different from the one that unit test code uses. Main code uses an Oracle DB and the test code uses an in-memory Derby.
Running unit tests was updating the Oracle DB (!) and I eventually managed to fix that by using two different persistence-units in the XML files.

However, I don't understand why that fixed the problem. I manually create and shut down the entity managers and they are not running concurrently. I'm pretty sure Maven (or the way I set it up) doesn't mess up the resources (XML files). In fact by looking at Maven's debug output I can see it's using the right XML file for unit tests.

Could someone enlighten me, please?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points