0

I'm trying to get running a Spring MVC web application that depends on another jar containing Hibernate (persistence.xml and annotations) logic, to keep thigns separated.

Some time ago this jar with Hibernate logic (let's call it "main") was a standalone app which worked perfectly. Now both projects (web project and "main") have been ported to Spring, but now no access to entities is possible. I think something is messed up with configuration files of Hibernate or Spring.

The error appears always, for example: MVC Controller -> call to a service in "main" to retrieve an entity -> exception thrown "Not an entity"

The exception thrown is:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Not an entity: class com.whatever.echoes.main.model.ocr.OcrDocumentModel

The error seems to happen in this line:

org.hibernate.ejb.metamodel.MetamodelImpl.entity(MetamodelImpl.java:184)

In the web.xml of the webapp, inside the "context-param" tag, the spring context configuration files of both projects are being loaded:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/root-context.xml
            classpath:META-INF/main-spring-config.xml
        </param-value>
    </context-param>

And on the "main" spring configuration i have:

    <context:component-scan base-package="com.whatever.echoes.main.model" />
    <context:spring-configured />
    <context:annotation-config />        

    <bean id="modelService" class="com.whatever.echoes.servicelayer.model.impl.ModelServiceImpl" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="docmodel" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>

    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />     
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <tx:annotation-driven transaction-manager="transactionManager" />

And my persistence unit is:

<persistence-unit name="docmodel" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>        
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/echoes"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="whatever"/>

            <!-- Hibernate specific settings -->
            <property name="hibernate.connection.pool_size" value="1"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="show_sql" value="true"/>
            <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
        </properties>
    </persistence-unit>

0 Answers0