-->
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.  [ 6 posts ] 
Author Message
 Post subject: error in hibernatetools hbm2java converting hbm to ejb3
PostPosted: Mon Sep 11, 2006 7:58 am 
Newbie

Joined: Tue May 16, 2006 3:35 pm
Posts: 7
Hello! I have several *.hbm.xml-Files and want convert them into ejb3-annotated java-files with hibernatetools 3.2.0.beta7. Two Entities (Entity3 and Entity10) are 1:1 connected. I followed the instructions of hibernate-reference implementing the hbm-1:1-relations:

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">
<hibernate-mapping>
  <class name="db.entities.Entity03" table="Entity03">
       
        <id name="idEntity03" type="int">
          <column name="idEntity03" />
          <generator class="native" />
        </id>
                
        <property name="attribute0" type="java.lang.String">
          <column name="attribute0" not-null="true" />
        </property>
                     
        <one-to-one name="entity10_11b" class="db.entities.Entity10" property-ref="entity03_11a"/>        
  </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="db.entities.Entity10" table="Entity10">
       
        <id name="idEntity10" type="int">
          <column name="idEntity10" />
          <generator class="native" />
        </id>
                
        <many-to-one name="entity03_11a" class="db.entities.Entity03" column="fk_idEntity03_11a" unique="true" />      
  </class>
</hibernate-mapping>


Here is en excerpt out of my ant-file:

Code:
<hibernatetool destdir="${destdir}">
  <configuration configurationfile="${destdir}/hibernate.cfg.xml" />
  <hbm2java jdk5="true" ejb3="true" />
</hibernatetool>


This is my hibernate.cfg.xml:

Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN/"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
      <mapping resource="db/manager/hibernate/Entity00.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity01.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity02.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity03.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity04.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity05.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity06.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity07.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity08.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity09.hbm.xml"/>
      <mapping resource="db/manager/hibernate/Entity10.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


Unfortunately I get the following output for my Entity03.java after conversion:

Code:
package db.entities;
// Generated 11.09.2006 13:31:07 by Hibernate Tools 3.2.0.beta7


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Columns;

/**
* Entity03 generated by hbm2java
*/
@Entity
@Table(name="Entity03"
)
public class Entity03  implements java.io.Serializable {

    // Fields   

     private int idEntity03;
     private String attribute0;
     private Entity10 entity10_11b;

     // Constructors

    /** default constructor */
    public Entity03() {
    }

   /** minimal constructor */
    public Entity03(String attribute0) {
        this.attribute0 = attribute0;
    }
    /** full constructor */
    public Entity03(String attribute0, Entity10 entity10_11b) {
       this.attribute0 = attribute0;
       this.entity10_11b = entity10_11b;
    }
   
    // Property accessors
     @Id @GeneratedValue
   
    @Column(name="idEntity03", unique=false, nullable=false, insertable=true, updatable=true)
    public int getIdEntity03() {
        return this.idEntity03;
    }
   
    public void setIdEntity03(int idEntity03) {
        this.idEntity03 = idEntity03;
    }
   
    @Column(name="attribute0", unique=false, nullable=false, insertable=true, updatable=true)
    public String getAttribute0() {
        return this.attribute0;
    }
   
    public void setAttribute0(String attribute0) {
        this.attribute0 = attribute0;
    }
   
    @Columns(  } )
    public Entity10 getEntity10_11b() {
        return this.entity10_11b;
    }
   
    public void setEntity10_11b(Entity10 entity10_11b) {
        this.entity10_11b = entity10_11b;
    }
}


The error is at "@Columns( } )". Seems, there is a bug in hibernatetools for converting 1:1-relations into ejb3-java-Files out of hbm-files. Can anyone help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 8:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
most likely a bug.

try and fix it in the .ftl files and/or submit a bugreport at our jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 5:04 am 
Newbie

Joined: Tue Jun 12, 2007 4:45 am
Posts: 2
I run into same problem while using the mojo hibernate3-maven-plugin for maven2.

I am generating the POJOs with annotations from *.hbm.xml file with hibernate3:hbm2java target.

I am able to reproduce this:

Code:
<class name="Person" table="PERSON">
        <id name="id" type="long" column="PERSON_ID">
            <meta attribute="use-in-equals">true</meta>
            <meta attribute="scope-set">protected</meta>
            <generator class="native" />
        </id>
             
   <many-to-one name="address"
           column="ADDRESS_FK"
           unique="true" class="Address"/>   
</class>

<class name="Address" table="ADDRESS">
        <id name="id" type="long" column="ADDRESS_ID">
            <meta attribute="use-in-equals">true</meta>
            <meta attribute="scope-set">protected</meta>
            <generator class="native" />
        </id>
          
   <[color=darkred]one-to-one[/color] name="person" property-ref="address" class="Person" /> 
</class>


This will output this in the Address.java:
Code:
[color=red]@Columns(  } )[/color]
public Person getPerson() {
    return this.person;
}


this is the related configuration part of the maven-plugin:
Code:
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.0-alpha-1</version>
        <configuration>
          <components>
            <component>
              <name>hbm2ddl</name>
              <implementation>annotationconfiguration</implementation>
            </component>
            <component>
              <name>hbm2java</name>
              <outputDirectory>src/main/java/</outputDirectory>
              <implementation>annotationconfiguration</implementation>
            </component>
          </components>
          <componentProperties>
            <jdk5>true</jdk5>
            <ejb3>true</ejb3>
            <outputfilename>create-db.sql</outputfilename>
            <format>true</format>
            <export>false</export>
          </componentProperties>
        </configuration>
      </plugin>


Is there a way to make hibernate-tools work correctly ???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 5:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes- fix the template, submit it to jira as a patch with a testcase and consider it done.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 7:29 am 
Newbie

Joined: Tue Jun 12, 2007 4:45 am
Posts: 2
Sorry, but hibernate is quite new for me.

How i find the template which is responsible for this issue? How to change it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 8:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its one of those in pojo/*.ftl inside hibernate-tools.jar.

you might need to look into to the EntityPojoClass.java too - for that you would need to check out the sources of hibernatetools.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.