1

I am developing a project using spring 4.2.2.RELEASE hibernate 5.0.2.Final and deploying the same on jboss Application server 7.1.1. I have to use jboss for deployment this is the hard requirement.

I don't want to use annotations to configure JPA entities ( this is a hard requirement) so for that I define a orm.xml file mapping

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
                 version="2.0">

    <description>OR Mapping</description>
    <persistence-unit-metadata>
        <xml-mapping-metadata-complete />
    </persistence-unit-metadata>
    <mapped-superclass class="com.lba.backend.rest.models.IdentifiableEntity">
        <attributes>
            <id name="id" />
        </attributes>
    </mapped-superclass>

    <entity class="com.company.rest.models.User">
        <table name="MyUser" />
        <attributes>
            <id name="id" />
            <basic name="username" />
            <basic name="firstName" />
            <basic name="lastName" />
            <basic name="image" />
        </attributes>
    </entity>

After defining this mapping, when I deploy the war file to jboss 7.1.1 application server I am getting below exception while server startup.

I even had a look at the hibernate source code, and this is the line AnnotationProxy#L87-89 that is throwing exception

if ( processedValuesFromDescriptor != descriptor.numberOfElements() ) {
            throw new RuntimeException( "Trying to instanciate " + annotationType + " with unknown elements" );
        }

When I remove the table element from xml file, it works fine for this but than it will throw the same exception for

<join-column name="roleId" insertable="false" updatable="false" />

I wrote Junit4 test cases for my controllers and services and this doesn't occur there. I used spring mvc test framework for writing unit tests using SpringJUnit4ClassRunner class.

Does anybody has any idea why I am getting this exception ?

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/backend-rest-1.0]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myEmf' defined in ServletContext resource [/WEB-INF/application-context.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Trying to instanciate interface javax.persistence.Table with unknown elements
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1048) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:825) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) [spring-context-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Caused by: java.lang.RuntimeException: Trying to instanciate interface javax.persistence.Table with unknown elements
    at org.hibernate.annotations.common.annotationfactory.AnnotationProxy.getAnnotationValues(AnnotationProxy.java:88) [hibernate-commons-annotations-5.0.0.Final.jar:5.0.0.Final]
    at org.hibernate.annotations.common.annotationfactory.AnnotationProxy.<init>(AnnotationProxy.java:69) [hibernate-commons-annotations-5.0.0.Final.jar:5.0.0.Final]
    at org.hibernate.annotations.common.annotationfactory.AnnotationFactory.create(AnnotationFactory.java:80) [hibernate-commons-annotations-5.0.0.Final.jar:5.0.0.Final]
    at org.hibernate.annotations.common.annotationfactory.AnnotationFactory.create(AnnotationFactory.java:53) [hibernate-commons-annotations-5.0.0.Final.jar:5.0.0.Final]
    at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.getTable(JPAOverriddenAnnotationReader.java:2780) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.initAnnotations(JPAOverriddenAnnotationReader.java:345) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.isAnnotationPresent(JPAOverriddenAnnotationReader.java:314) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.isAnnotationPresent(JavaXAnnotatedElement.java:60) [hibernate-commons-annotations-5.0.0.Final.jar:5.0.0.Final]
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.categorizeAnnotatedClass(AnnotationMetadataSourceProcessorImpl.java:115) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:104) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.<init>(MetadataBuildingProcess.java:147) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:141) [hibernate-core-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:770) [hibernate-entitymanager-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:797) [hibernate-entitymanager-5.0.2.Final.jar:5.0.2.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:135) [hibernate-entitymanager-5.0.2.Final.jar:5.0.2.Final]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) [spring-orm-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) [spring-orm-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) [spring-beans-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    ... 20 more

21:39:25,475 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Error listenerStart
21:39:25,476 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Context [/backend-rest-1.0] startup failed due to previous errors
21:39:25,488 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/backend-rest-1.0]] (MSC service thread 1-2) Closing Spring root WebApplicationContext
21:39:25,498 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.web.deployment.default-host."/backend-rest-1.0": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/backend-rest-1.0": JBAS018040: Failed to start context
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Syed
  • 1,461
  • 3
  • 19
  • 37
  • It is possible you have fields in your Entity class that does not match with what you have declared in your orm.xml, or perhaps have some fields in your Entity class that aren't declared in orm.xml. It would help if you can post your Entity class code. – Ish Oct 19 '15 at 18:01
  • 1
    @Ish I have more than 40 entities. And how it is working in test class. The jboss 7 has hibernate 4.0.1 bundled with JPA 2.0 and hibernate 5.0.2 has JPA 2.1. Is this is the problem ? Can you point to docs. I even replaced jboss provided hibernate jars with new one reading from [This](http://stackoverflow.com/questions/23294492/exclude-jpa-2-0-from-jboss-7-1-in-order-to-use-hibernate-4-3) – Syed Oct 19 '15 at 18:16

1 Answers1

2

Syed, as the link that you posted suggests, the problem is mixing JPA 2.0 and JPA 2.1 libs. Your tests are probably working because on the classpath the 2.1 libs show first. On your application server the 2.0 libs show first (probably hibernate-jpa-2.0-api) and you get the error

I had this same problem but in a different setup. My solution was to exclude from my pom.xml the transitive dependency to the old hibernate-jpa-2.0-api lib:

<dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa-codegen</artifactId>
    <version>4.1.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Community
  • 1
  • 1
matias.g.rodriguez
  • 849
  • 11
  • 14