Objects not showing after moving them to the external jar package

In my Java / Seam / JbossAS application, I decided to film my Model classes (hibernate) and moved them to another project. The project creates model.jar, which is then used by the main application. The identification of model.jar is permitted by Ivy. Creating the main application using Ant works without problems. Then I will copy the model.jar file manually to the directory 'mainapp.ear / lib'. Subsequently, I deploy the application, and there are no problems (although I noticed that there is no information about the mappings found). But when I want to log in, I get an 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] 

At the same time, there were no code changes, they just squeezed some of the classes into the bank. Does this mean that I need the source code for the Model classes when compiling the main application?

+6
source share
2 answers

EntityManagerFactory created to scan objects only from jar with the file /META-INF/persistence.xml .

To scan other cans you need 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 .

+5
source

Also check that the hibernate mappings are correctly placed in the hibernate configuration file. Note that the hibernate mapping resources or classes are related to the location of the hibernate.cfg.xml file.

0
source

Source: https://habr.com/ru/post/888335/


All Articles