Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 2.0-M2
-
Fix Version/s: None
-
Component/s: Persistence Layer
-
Labels:None
-
Environment:using jpa-hibernate
Description
When you run a (simple) test case in a new created appfuse project, using JPA-Hibernate for persistence, you get;
java.lang.IllegalArgumentException: Unknown entity: com.vgelder.model.ExtendedBase
So probably there's a problem in loading the EntityManager.
No (own) testcases can run.
You can run the attached project and see the bug:
mvn test -Dtest=ExtendedBaseTest -Ddao.framework=jpa-hibernate
also see http://www.nabble.com/jpa%3A-...does-not-have-an-%40Id-or-%40EmbeddedId-annotation.-tf2972763s2369.html#a8638726 for a little bit of discussion about it.
java.lang.IllegalArgumentException: Unknown entity: com.vgelder.model.ExtendedBase
So probably there's a problem in loading the EntityManager.
No (own) testcases can run.
You can run the attached project and see the bug:
mvn test -Dtest=ExtendedBaseTest -Ddao.framework=jpa-hibernate
also see http://www.nabble.com/jpa%3A-...does-not-have-an-%40Id-or-%40EmbeddedId-annotation.-tf2972763s2369.html#a8638726 for a little bit of discussion about it.
-
Hide
- jpatest.zip
- 25/Jan/07 2:26 PM
- 52 kB
- Marcel Rokers
-
- jpatest/.classpath 10 kB
- jpatest/.project 0.3 kB
- jpatest/.../org.eclipse.jdt.core.prefs 0.2 kB
- jpatest/pom.xml 16 kB
- jpatest/README.txt 0.8 kB
- jpatest/src/main/.../com/vgelder/App.java 0.1 kB
- jpatest/src/main/.../vgelder/model/Base.java 2 kB
- jpatest/src/main/.../model/ExtendedBase.java 0.5 kB
- jpatest/.../applicationContext-resources.xml 2 kB
- jpatest/.../ApplicationResources.properties 7 kB
- jpatest/.../ApplicationResources_de.properties 9 kB
- jpatest/.../ApplicationResources_en.properties 0.1 kB
- jpatest/.../ApplicationResources_es.properties 8 kB
- jpatest/.../ApplicationResources_fr.properties 8 kB
- jpatest/.../ApplicationResources_it.properties 8 kB
- jpatest/.../ApplicationResources_nl.properties 7 kB
- jpatest/.../ApplicationResources_pt.properties 8 kB
- jpatest/.../ApplicationResources_pt_BR.properties 8 kB
- jpatest/.../ApplicationResources_zh.properties 5 kB
- jpatest/.../ApplicationResources_zh_CN.properties 5 kB
- jpatest/src/main/resources/ehcache.xml 3 kB
- jpatest/src/.../resources/hibernate.cfg.xml 0.5 kB
- jpatest/src/.../resources/jdbc.properties 0.4 kB
- jpatest/src/main/resources/log4j.xml 1 kB
- jpatest/src/.../resources/mail.properties 0.2 kB
- jpatest/src/.../META-INF/persistence.xml 0.5 kB
- jpatest/src/.../applicationContext.xml 0.6 kB
- jpatest/src/.../WEB-INF/faces-config.xml 9 kB
- jpatest/src/main/.../WEB-INF/menu-config.xml 1 kB
- jpatest/src/main/.../WEB-INF/urlrewrite.xml 0.3 kB
Activity
Hide
Matt Raible
added a comment -
+1 to your proposed fix. I think I tried a similar fix for APF-571, but it didn't work. I'll try again.
Show
Matt Raible
added a comment - +1 to your proposed fix. I think I tried a similar fix for APF-571, but it didn't work. I'll try again.
Hide
Matt Raible
added a comment -
It looks like this fix works for APF-571 as well. Note that I had to copy hibernate.cfg.xml into services/src/test/resources as well. I believe most of this works now thanks to the warpathExcludes that Mike added to the warpath plugin.
Show
Matt Raible
added a comment - It looks like this fix works for APF-571 as well. Note that I had to copy hibernate.cfg.xml into services/src/test/resources as well. I believe most of this works now thanks to the warpathExcludes that Mike added to the warpath plugin.
Hide
Bryan Noll
added a comment -
Resolved as discussed in prior comment. Will close the issue once I make the updates to archetype-generated files.
Committed revision 2463.
Committed revision 2463.
Show
Bryan Noll
added a comment - Resolved as discussed in prior comment. Will close the issue once I make the updates to archetype-generated files.
Committed revision 2463.
Show
Bryan Noll
added a comment - Committed revision 2473
========================
This is the current situation in trunk as of now.
In the jpa-hibernate module, persistence.xml and applicationContext-xml live here:
- src/main/resources/META-INF/persistence.xml
- src/main/resources/applicationContext-dao.xml
In the archetype:
- persistence.xml lives in 'src/main/resources/META-INF'
- applicationContext-dao.xml does not exist
Result:
========
Fails with java.lang.IllegalArgumentException: Unknown entity: com.mycompany.model.Person (another issue with the same cause arises when the hbm2ddl plugin is changed from annotationconfiguration to jpaconfiguration)
################################################################################
Scenario 2 (the fix):
======================
This is the fix I propose.
In the jpa-hibernate module, persistence.xml and applicationContext-xml are here:
- src/test/resources/META-INF/persistence.xml (test tree - meaning it won't get bundled in the jar which fixes the problem)
- src/main/resources/applicationContext-dao.xml (main tree)
In the archetype:
- src/main/resources/META-INF/persistence.xml (main tree)
- applicationContext-dao.xml does not exist
Result:
========
Works
*** NOTE: the persistence.xml file does NOT have to have Person added as a persistent entity via a <class> element. Note the following logging output:
[basic-struts] INFO [main] Ejb3Configuration.scanForClasses(652) | found EJB3 Entity bean: com.mycompany.model.Person
That being said, if User and Role aren't there, it will not work. I believe this is because User and Role are in a different jar than Person.
In addition, I believe we should update the pom.xml that the archetype generates, adding the following, very similar to the OpenSessionInView vs. OpenEntityManagerInView issue in web.xml:
<implementation>annotationconfiguration</implementation>
<!-- Use jpaconfiguration if your going the -Ddao.framework=jpa-hibernate route. -->
<!--<implementation>jpaconfiguration</implementation>-->
Last but not least, I will add some comments to the persistence.xml file that the archetype generates, explaining that a user is not required to add <class>com.mycompany.model.Person</class> to it, because the Ejb3Configuration.scanForClasses method will handle it, but that they can for clarity if they like.