Hi,
I Struggle an bit with the conversion from an old project with hibernate-core and hbm.xml files to an project with hibernate entity manager (version 4.3.6.Final).
In a test situation I've two mapping hbm.xml mapping files where one is mentioned in the persistance.xml file one of the properties is the hibernate.hbm2ddl.auto = create..The contents of this mapping file is an single class that must be used in that persistence-unit. However, starting up hibernate with Persistence.createEntityManagerFactory(name); results in two tables from both the hbm.xml files. Using <class> and exclude-unlisted-classes=true, it does not matter always there are two classes instead of one and both the classes can be used with the generated enty-manager.
What do i wrong.
Greetings,
Persistence.xml:
Code:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="test_PU" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/address.hbm.xml</mapping-file>
<class>model.Address</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/test" />
<property name="javax.persistence.jdbc.user" value="jboss" />
<property name="javax.persistence.jdbc.password" value="jboss" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
dependencies pom file :
Code:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.4.Final</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.2.0.GA</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
</dependencies>
not used person.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2-sep-2014 6:45:15 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="model.Person" table="PERSON">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="name" column="C_NAME" />
<property name="email" column="C_EMAIL" />
</class>
</hibernate-mapping>
ussed address.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Address">
<id name="id" column="C_ID">
<generator class="native" />
</id>
<property name="name" column="C_NAME" />
<property name="houseNumber" column="C_HOUSE_NUMBER" />
<property name="zipCode" column="C_ZIP_CODE" />
<property name="city" column="C_CITY" />
</class>
</hibernate-mapping>