8

So, I have a basic Java SE program with dependency injection using Weld 1.2.

Everything is working fine, until I throw Hibernate into the mix, with the following pom.xml dependency entries:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
</dependency>
<dependency>
    <groupId>org.jboss.weld.se</groupId>
    <artifactId>weld-se</artifactId>
    <version>2.2.4.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.6.Final</version>
</dependency>

Hibernate being the added dependency, making it break. This is my entry class:

public class EntryPoint {
    public static void main( String[] ARGV ) {
        Weld weld = new Weld();
        WeldContainer container = weld.initialize();

        Application application = container.instance().select(Application.class).get();

        application.testFetch();

        weld.shutdown();
    }
}

When I try to run it after including Hibernate dependency, this is my output:

Sep 11, 2014 11:13:44 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.2.4 (Final)
Sep 11, 2014 11:13:44 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: org.jboss.jandex.ClassInfo.hasNoArgsConstructor()Z
    at org.jboss.weld.executor.AbstractExecutorServices.checkForExceptions(AbstractExecutorServices.java:66)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:43)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:51)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer.addClasses(ConcurrentBeanDeployer.java:62)
    at org.jboss.weld.bootstrap.BeanDeployment.createClasses(BeanDeployment.java:209)
    at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:351)
    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76)
    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:157)
    at com.mybeautycompare.integration.EntryPoint.main(EntryPoint.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.NoSuchMethodError: org.jboss.jandex.ClassInfo.hasNoArgsConstructor()Z
    at org.jboss.weld.environment.se.discovery.WeldSEClassFileInfo.<init>(WeldSEClassFileInfo.java:65)
    at org.jboss.weld.environment.se.discovery.WeldSEClassFileServices.getClassFileInfo(WeldSEClassFileServices.java:85)
    at org.jboss.weld.bootstrap.FastAnnotatedTypeLoader.loadAnnotatedType(FastAnnotatedTypeLoader.java:61)
    at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Line 24 in my EntryPoint class is: WeldContainer container = weld.initialize();

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Wrench
  • 4,070
  • 4
  • 34
  • 46

2 Answers2

25

This has nothing to do with Hibernate. You're missing jandex from your classpath, which is required in Weld 2.2.x. Verify that you end up with a jandex 1.2 jar on your classpath after building.

Since you're using maven, add this to your pom.xml:

<dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jandex</artifactId>
    <version>1.2.2.Final</version>
</dependency>

Also related:

Why is Hibernate 4.2 using jandex and classmate if its Maven POM defines them as test scope?

Community
  • 1
  • 1
John Ament
  • 11,595
  • 1
  • 36
  • 45
2

For people who have same issue with the latest versions of Weld and Hibernate:

Both Weld and Hibernate have dependency on Jandex but with different versions, you need to exclude Jandex dependency from the hibernates dependency:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.jboss</groupId>
            <artifactId>jandex</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Good Luck

Jalal Kiswani
  • 738
  • 5
  • 11
  • Thanx a lot for these answers. For me it seems more clear to exclude the dependency from hibernate. However it appears to be necessary to explicitely add jandex as despendency as stated in the accepted answer. The solution also works for artifact hibernate-core instead of the now deprecated hibernate-entitymanager. Tested with hibernate-core 6.1.6.Final, weld-se-core 5.1.0 Final and jandex 3.0.5. – r-uu Dec 16 '22 at 10:13