AppFuse JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
  • AppFuse
  • APF-593

JPA: "Unknown entity" in testcases (persistence.xml not parsed?)

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical 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.
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    jpatest.zip
    25/Jan/07 2:26 PM
    52 kB
    Marcel Rokers
    1. File
      jpatest/.classpath 10 kB
    2. File
      jpatest/.project 0.3 kB
    3. File
      jpatest/.../org.eclipse.jdt.core.prefs 0.2 kB
    4. XML File
      jpatest/pom.xml 16 kB
    5. Text File
      jpatest/README.txt 0.8 kB
    6. Java Source File
      jpatest/src/main/.../com/vgelder/App.java 0.1 kB
    7. Java Source File
      jpatest/src/main/.../vgelder/model/Base.java 2 kB
    8. Java Source File
      jpatest/src/main/.../model/ExtendedBase.java 0.5 kB
    9. XML File
      jpatest/.../applicationContext-resources.xml 2 kB
    10. File
      jpatest/.../ApplicationResources.properties 7 kB
    11. File
      jpatest/.../ApplicationResources_de.properties 9 kB
    12. File
      jpatest/.../ApplicationResources_en.properties 0.1 kB
    13. File
      jpatest/.../ApplicationResources_es.properties 8 kB
    14. File
      jpatest/.../ApplicationResources_fr.properties 8 kB
    15. File
      jpatest/.../ApplicationResources_it.properties 8 kB
    16. File
      jpatest/.../ApplicationResources_nl.properties 7 kB
    17. File
      jpatest/.../ApplicationResources_pt.properties 8 kB
    18. File
      jpatest/.../ApplicationResources_pt_BR.properties 8 kB
    19. File
      jpatest/.../ApplicationResources_zh.properties 5 kB
    20. File
      jpatest/.../ApplicationResources_zh_CN.properties 5 kB
    21. XML File
      jpatest/src/main/resources/ehcache.xml 3 kB
    22. XML File
      jpatest/src/.../resources/hibernate.cfg.xml 0.5 kB
    23. File
      jpatest/src/.../resources/jdbc.properties 0.4 kB
    24. XML File
      jpatest/src/main/resources/log4j.xml 1 kB
    25. File
      jpatest/src/.../resources/mail.properties 0.2 kB
    26. XML File
      jpatest/src/.../META-INF/persistence.xml 0.5 kB
    27. XML File
      jpatest/src/.../applicationContext.xml 0.6 kB
    28. XML File
      jpatest/src/.../WEB-INF/faces-config.xml 9 kB
    29. XML File
      jpatest/src/main/.../WEB-INF/menu-config.xml 1 kB
    30. XML File
      jpatest/src/main/.../WEB-INF/urlrewrite.xml 0.3 kB
    Showing 30 of 39 items Download Zip
    Show
    Zip Archive
    jpatest.zip
    25/Jan/07 2:26 PM
    52 kB
    Marcel Rokers

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Source
Hide
Permalink
Bryan Noll added a comment - 08/Feb/07 11:30 AM
Scenario 1 (how it is):
========================

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.

Show
Bryan Noll added a comment - 08/Feb/07 11:30 AM Scenario 1 (how it is): ======================== 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.
Hide
Permalink
Matt Raible added a comment - 08/Feb/07 11:38 AM
+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 - 08/Feb/07 11:38 AM +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
Permalink
Matt Raible added a comment - 08/Feb/07 12:12 PM
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 - 08/Feb/07 12:12 PM 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
Permalink
Bryan Noll added a comment - 08/Feb/07 12:30 PM
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 - 08/Feb/07 12:30 PM Resolved as discussed in prior comment. Will close the issue once I make the updates to archetype-generated files. Committed revision 2463.
Hide
Permalink
Bryan Noll added a comment - 12/Feb/07 9:41 AM
Committed revision 2473
Show
Bryan Noll added a comment - 12/Feb/07 9:41 AM Committed revision 2473

People

  • Assignee:
    Bryan Noll
    Reporter:
    Marcel Rokers
Vote (0)
Watch (0)

Dates

  • Created:
    25/Jan/07 2:26 PM
    Updated:
    12/Feb/07 9:41 AM
    Resolved:
    08/Feb/07 12:30 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for AppFuse. Try JIRA - bug tracking software for your team.