-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: multiple mapping files
PostPosted: Tue Sep 02, 2014 2:09 am 
Newbie

Joined: Mon Mar 09, 2009 2:52 am
Posts: 4
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>


Top
 Profile  
 
 Post subject: Re: multiple mapping files
PostPosted: Fri Sep 05, 2014 3:51 pm 
Newbie

Joined: Mon Mar 09, 2009 2:52 am
Posts: 4
Ok found it my self. when the property <property name="hibernate.archive.autodetection" value=""/> the value is always "class, hbm" So when you not want that autodetection should be done you must put the an empty string into the value.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.