This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Can't create persistence  unit in test class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Can Watch "Can New topic
Author

Can't create persistence unit in test class.

sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
Hi,

In my junit test class, I can't use Persistence.createEntityManagerFactory to create an entityManager.

This is the junit test class:



When I execute this file, it failed at emf = Persistence.createEntityManagerFactory("TestDatePU");

Error message is:
caused error: org/hibernate/internal/util/xml/Origin



Here is my persistence.xml file:


Facade class:


The sample project of this test is available, but I don't know how to attach it here. If anyone interest the project, please contact me.

Any suggestion is very appreciated.

Sincerely
Sam
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Was there more to the error than
caused error: org/hibernate/internal/util/xml/Origin

I'd expect to see a stack trace or class not found error.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
Thank you for your reply.
Here is stack of trace when running it with " mvn -X -Dmaven.test.skip=false clean install ":

[INFO] TestDate .......................................... SUCCESS [0.281s]
[INFO] TestDate-ejb ...................................... FAILURE [2.520s]
[INFO] TestDate-web ...................................... SKIPPED
[INFO] TestDate-ear ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.935s
[INFO] Finished at: Sun Mar 24 11:35:09 EST 2013
[INFO] Final Memory: 19M/46M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project TestDate-ejb: There are test failures.
[ERROR]
[ERROR] Please refer to C:\work\NetBeansProjects\TestDate\TestDate-ejb\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project TestDate-ejb: There are test failures.

Please refer to C:\work\NetBeansProjects\TestDate\TestDate-ejb\target\surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to C:\work\NetBeansProjects\TestDate\TestDate-ejb\target\surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:87)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:641)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:615)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:137)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :TestDate-ejb
sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
A different exception is shown when I execute the test within Netbeans editor.
Please see attachment for detail.
Thanks
Sam



[Thumbnail for exception-within-editor.png]

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Sam,
That helps a lot. On line 5 of the NetBeans stack trace you do in fact get a NoClassDefFound error. (For Maven, the stack trace tells you to see the surefire reports directory for the REAL stack trace.) That class is in Hibernate Core. Check you have that jar in your classpath.

I'm going to move this to the BUild forum since it isn't a testing issue per se. And I'm starting to suspect an Ant/Maven issue so you'll get better help there.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

The Maven output looks like you have a master POM with submodules. The output for the submodule that failed (TestDate-ejb) would be more helpful in resolving this problem.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't create persistence unit in test class.
 
Similar Threads
Problem in generating the Primary Key using a Sequence
JPA with JSF
JPA not working with EJB3
javax.persistence.PersistenceException: No Persistence provider for EntityManager - WebApplication
Query after JPA collective update not getting updates