1

We'd like to get rid of having to specify all the jar files or individual classes in persistence.xml and <property name="hibernate.archive.autodetection" value="class"/> doesn't seem to work, at least Hibernate doesn't pick up any classes that are not in any of the mentioned jar files or in the archive containing persistence.xml.

So the idea was to scan for entities ourselves and provide Hibernate with all the detected classes.

The basic approach would have been:

  • use a CDI extension to pick up all classes annotated with @Entity (this works)
  • use a Hibernate integrator to register the classes

However, there are two problems as it seems:

  1. The integrator runs before the CDI extension so the order doesn't fit.
  2. Logs indicate that Hibernate builds the persistence unit even before running the integrators thus adding classes in the integrator seems to be too late, even if we could solve or work around problem 1 (e.g. by scanning the classpath ourselves).

Basically the question is: How would we programmatically add persistent classes to the Hibernate configuration in a JBoss 7 or Wildfly environment?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Thomas
  • 87,414
  • 12
  • 119
  • 157

1 Answers1

0

As you've already stated, hibernate may be initialized before CDI is. There is a little workaround that removes the need to specify each and every bean, but only JARs. Persistence.xml has a <jar-file>jarName</jar-file> tag that enables you to specify the jars that should be scanned for persistence entities.

Detailed answer by Pascal Thivent Do I need <class> elements in persistence.xml?

Sometimes, this didn't work for me until I declared path to JARS like <jar-file>lib/someJar.jar</jar-file>

Community
  • 1
  • 1
Pavel Pscheidl
  • 334
  • 3
  • 11
  • Yes, the jar-file tag is what we're using currently. But as I said, we'd like to get rid of that if possible. :) - Pascal also mentions `hibernate.archive.autodetection` but that unfortunately didn't work, which might be due to a setup problem, i.e. Hibernate doesn't/can't scan the entire classpath. – Thomas Mar 14 '16 at 08:33