David Hofmann
David Hofmann

Reputation: 5775

Wildfly 8.2 fails scanning entities inside WEB-INF/lib/*.jar directory. Is this the expected behavior?

I was deploying a war that contained the entities inside the WEB-INF/classes directory, but now I moved those entities to a separate proyect/module and now the entities reside inside WEB-INF/lib/*.jar

After the change wildfly failed to scan the entities producing errors while deploying.

I then tried adding

<class>class.inside.webinf.lib.Entity1</class>

tags inside my persistence.xml file and everything deployed correctly.

Full persistence.xml at file.war/WEB-INF/classes/META-INF/persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="pu" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/jboss/datasources/sgsdscore</jta-data-source>

      <class>io.ingenia.sgsds.score.entity.Entity1</class>
      <class>io.ingenia.sgsds.score.entity.EntityN</class>

      <exclude-unlisted-classes>false</exclude-unlisted-classes> 
      <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.jdbc.batch_size" value="200"/> 
         <property name="hibernate.order_inserts" value="true" />
         <property name="hibernate.order_updates" value="true" />

         <property name="hibernate.cache.use_second_level_cache" value="true"/>
      </properties>
   </persistence-unit>
</persistence>

Am I missing something ?

EJBs inside WEB-INF/lib/*.jar where successfuly scanned though...

Upvotes: 0

Views: 1121

Answers (3)

David Hofmann
David Hofmann

Reputation: 5775

I guess that this answer also answers my question https://stackoverflow.com/a/6263592/39998

It's fine to have the entities inside the lib directory like WEB-INF/lib/entities.jar, but then the persistence.xml file must be inside WEB-INF/lib/entities.jar/META-INF/persistence.xml

If the persistence.xml file is inside WEB-INF/classes/META-INF/persistence.xml then the automatic scanning will occurr only inside WEB-INF/classes/*

Makes sense. (kind of...)

Upvotes: 2

John Ament
John Ament

Reputation: 11733

It's hard to say without seeing your persistence.xml file. You can specify exclude-unlisted-classes which will say only look at the listed classes. You must use jar-file to indicate what JAR files to scan (it's not clear from your question if you're already doing that.

Upvotes: 1

Harald Wellmann
Harald Wellmann

Reputation: 12885

In general, this should work. I'm using JPA entity classes from a WEB-INF/lib/*.jar in most of my projects.

However, there may be issues when some of your classes are not in the same JAR as the persistence.xml descriptor.

Upvotes: 1

Related Questions