1

I work with maven on a spring-data, spring security, jpa, hibernate project:

In my project (pom type) i have all dependencies defined in the POM file -> OK In the first module (jar type), i have all packages : - hibernate package - repository package - services package - etc...

In the second module (war type), i have : - controller package - database configuration - security configuration - etc...

In the POM of this second module, i added the first module dependency.

When i run this second module i got this error :

java.lang.IllegalArgumentException: Not an managed type: class com.mc.appcontacts.domain.hibernate.User

But if i move the hibernate package from the first module to the second module, it works !

Is it possible to keep the hibernate package in the first module ?

Because if i add others modules which are dependent of the first module (like the second in my exemple) i must duplicate the hibernate package in all new modules...not very cool (mainly if there is a change in the database structure)

Thank you for your help

anakin59490
  • 630
  • 1
  • 11
  • 28

1 Answers1

0

YES !!

I found !

I resume : In my applicationContext.xml, i import a database resource :

<!--  included Spring contexts -->   
<import resource="classpath:META-INF/contacts/contexts/db_context.xml"/>

In the db_context.xml, i declare a JPA entityManagerFactory (i refer to persistence.xml):

<!-- Declare a JPA entityManagerFactory -->
<bean id="entityManagerFactory"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath:META-INF/contacts/hibernate/persistence.xml" />
    <property name="persistenceUnitName" value="hibernatePersistenceUnit" />
    <property name="jpaVendorAdapter" ref="hibernateVendor" />
</bean>

In persistence.xml, i define a mapping file (ORM.xml):

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
    <property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
      .....
</properties>
<mapping-file>META-INF/contacts/hibernate/orm.xml</mapping-file>
</persistence-unit>
</persistence>

In this orm.xml file, i define....nothing :

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0" 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">
<persistence-unit-metadata>
    <persistence-unit-defaults>
    </persistence-unit-defaults>
</persistence-unit-metadata>
   </entity-mappings>

but it works if there are no maven module (only a maven project (with all packages and conf files) OR if the hibernate Package is present in each module !!

So this is my new orm.xml :

 <?xml version="1.0" encoding="UTF-8"?>
 <entity-mappings version="2.0" 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">

<package>com.mc.appcontacts.domain.hibernate</package>

<entity class="Client">
    <table name="client" />
 </entity>
 <entity class="Contact">
    <table name="contact" />
 </entity>
 <entity class="SystemUser">
    <table name="system_user" />
 </entity>
 <entity class="User">
    <table name="user" />
 </entity>
 <entity class="Userlogin">
    <table name="userlogin" />
 </entity>
 <entity class="Userauth">
    <table name="userauth" />
 </entity>
<!-- <persistence-unit-metadata>
    <persistence-unit-defaults>
    </persistence-unit-defaults>
</persistence-unit-metadata> -->
   </entity-mappings>

And it works with my hibernate package only defined in ContactCore module !

anakin59490
  • 630
  • 1
  • 11
  • 28