8

In my Java/Seam/JbossAS app, I decided to externalize my Model classes (hibernate entities) and moved them into another project. The project produces model.jar, which is then used by the main app. The model.jar dependency is resolved by Ivy. Building the main app with Ant works without problems. Then I copy manually the model.jar into 'mainapp.ear/lib' directory. Afterwards I deploy the app and there are no problems (although I notice that there are is no log info about found mappings). But when I want to login, I get the exception:

javax.el.ELException: javax.ejb.EJBTransactionRolledbackException:
    org.hibernate.hql.ast.QuerySyntaxException: AppUser is not
    mapped [select u from AppUser u where u.userName = :usernamePar]

There were no code changes in the meantime, just externalizing some of the classes into a jar. Does this mean, that I need the source code of the Model classes when compiling the main app?

user1293910asd
  • 153
  • 1
  • 12
  • Is your hibernate.cfg.xml file in your main app's root? – Rafa de Castro May 17 '11 at 16:02
  • @Rafa de Castro The Hibernate configuration is done thru the persistance.xml (the path is 'app.ear/app.jar/META-INF/persistence.xml') file, mappings are done via annotations - maybe this is the problem? – user1293910asd May 18 '11 at 07:42

2 Answers2

5

The EntityManagerFactory is built for scanning entities only from the jar that has a /META-INF/persistence.xml file into.

In order to scan other jars you have to use <jar-file>:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
   <persistence-unit name="manager1" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <mapping-file>ormap.xml</mapping-file>
      <jar-file>MyApp.jar</jar-file>
      <class>org.acme.Employee</class>
      <class>org.acme.Person</class>
      <class>org.acme.Address</class>
      <shared-cache-mode>ENABLE_SELECTOVE</shared-cache-mode>
      <validation-mode>CALLBACK</validation-mode>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      </properties>
   </persistence-unit>
</persistence>

See 2.2.1 Packaging in Hibernate doc.

Stefano Travelli
  • 1,889
  • 1
  • 15
  • 18
0

Also check if your hibernate mappings are correctly placed wrt hibernate config file. Note that hibernate mapping resources or classes are relative to the location of hibernate.cfg.xml file.

mod
  • 383
  • 5
  • 22