This content has been marked as final. Show 5 replies
Yes well, wait for an answer in the EclipseLink forum. JPA is only an API, it doesn't "do" anything. It is EclipseLink that is giving you troubles.
I would advise you to add more information to your Eclipse forum post, such as the persistence.xml file and the code which you use to obtain an entity manager.
I posted here because this might not be an EclipseLink issue.
After I wrote this post I ran my unit test from command line (I'm on OS X so from Terminal) instead of Eclipse. This is a Maven project so it was easy: mvn clean test
It ran fine. Then I tried it again and again, altogether 30 times(!) today and it was all fine with no errors when I ran it from the command line.
My Eclipse IDE, I usually use to run tests from, has obviously the JUnit plugin running, the m2e plugin, as this is a Maven project and all my project dependencies.
Maybe it couldn't handle all these, but as I said it's looking all fine from Terminal.
Here are the details of my setup anyway, to answer your question:
The unit test is using MySQL with InnoDB tables.
No schema name is set on entities but there is one in the JDBC connection string used in persistence.xml
<persistence-unit name="data-warehouse" transaction-type="RESOURCE_LOCAL">
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://rdbms.local:3306/test_cms?characterEncoding=utf8" />
<property name="javax.persistence.jdbc.user" value="..." />
<property name="javax.persistence.jdbc.password" value="..." />
<property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.weaving" value="false" />
<property name="eclipselink.cache.shared.default" value="false"/>
... used where I don't wanna disclose info, this is a proprietary project.
Typically for a resource (database) bound test like yours one would get more inconsistent results when running via maven directly from the command line than from the IDE. This is because the IDE usually runs your tests one at a time while maven may execute your tests in parallel. It is generally good to write your tests in such a way that it doesn't matter in how many are being run at the same time. I'm surprised you are using mysql here not an in memory database which would make these more integration tests that unit but I'm digressing ...
Check the maven defaults for whether it's forking or running parallel per class/test. That may be able to help you understand why it would only work when run using maven settings only.