-->
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: hbm2java for annotation from existing inheritance mapping
PostPosted: Sun Feb 05, 2006 6:48 pm 
Newbie

Joined: Sun Feb 05, 2006 6:24 pm
Posts: 7
Hello,

i have an inheritance mapping with joined subclass. This was generated by the hibernate reverse engineering tools and converted with xslt... this xml mapping is almost testet and works fine. Now i want to move to Annotation based mapping configuration and had the hope hbm2java would generate everything from the existing xml configuration, but in the generated code i could not see anything like @inheritance as i expected.

does hbm2java support inheritance mapping from an exisitng joined-subclasse configuration?


My base class hbm.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="de.infratour.hbm.Entity" table="entity" catalog="infratour">
        <id name="id" type="long">
<column name="id"/>
<generator class="identity"/>
</id>
        <many-to-one name="owner" class="de.infratour.hbm.Entity" fetch="select" unique="false" update="true" insert="true" optimistic-lock="true" not-found="exception" embed-xml="true">
            <column name="idOwner"/>
        </many-to-one>
...


one of my child classes hbm.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <joined-subclass extends="de.infratour.hbm.Entity" name="de.infratour.hbm.Address" table="address" catalog="infratour">
        <key column="id"/>
        <property name="country" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="country" length="40"/>
        </property>
        <property name="state" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="state" length="40"/>
        </property>
        <property name="postcode" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="postcode" length="20"/>
        </property>
        <property name="city" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="city" length="80"/>
        </property>
        <property name="street" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="street" length="80"/>
        </property>
        <property name="telPrivat" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="tel_privat" length="40"/>
        </property>
        <property name="telMobil" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="tel_mobil" length="40"/>
        </property>
        <property name="telBusiness" type="string" unique="false" update="true" insert="true" optimistic-lock="true" lazy="false">
            <column name="tel_business" length="40"/>
        </property>
   </joined-subclass>
</hibernate-mapping>



The generated code:

Code:
/**
* Entity generated by hbm2java
*/
@Entity
@Table(name="entity"
)

public class Entity  implements java.io.Serializable {


    // Fields   

     private long id;
     private Short version;

...

Code:

/**
* Address generated by hbm2java
*/
@Entity
@Table(name="address"
    ,catalog=""
)

public class Address extends de.infracore.hbm.Entity implements java.io.Serializable {


    // Fields   
...

Hibernate version:3.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 2:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you find features that is not covered in the conversion step then feel free to submit patches/jira issues.

p.s. why are you using xslt to do some of the "conversion"...what does that do ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 4:46 am 
Newbie

Joined: Sun Feb 05, 2006 6:24 pm
Posts: 7
The ourcome of hibernates reverse engineering for the above mentiioned address table was:

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>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
    <class name="de.infratour.hbm.Address" table="address" catalog="infratour">
        <id name="id" type="long">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <many-to-one name="entity" class="de.infratour.hbm.Entity" update="false" insert="false" fetch="select">
            <column name="id" not-null="true" unique="true" />
        </many-to-one>
        <property name="country" type="string">
            <column name="country" length="40" />
        </property>
        <property name="state" type="string">
            <column name="state" length="40" />
        </property>
        <property name="postcode" type="string">
            <column name="postcode" length="20" />
        </property>
        <property name="city" type="string">
            <column name="city" length="80" />
        </property>
        <property name="street" type="string">
            <column name="street" length="80" />
        </property>
        <property name="telPrivat" type="string">
            <column name="tel_privat" length="40" />
        </property>
        <property name="telMobil" type="string">
            <column name="tel_mobil" length="40" />
        </property>
        <property name="telBusiness" type="string">
            <column name="tel_business" length="40" />
        </property>
    </class>
</hibernate-mapping>



My xslt transformation generates the mentioned joined subclass mapping from this hbm.xml:

*replace the <class> mapping with <joined-subclass> mapping
*replace the <many-to-one> relations to the base Entity table with the <key> tag.

To avoid doing this for about 30 tables i have created a xslt stylesheet and an ant task for this... As mentioned in an other thread, the reverse engineering can not get the inheritance information from the database.

patches/jira issues... yes, i will have a look... but until now i'm not shure whether i left something out, or hbm2java does not support inheritance mapping with annotations... in the java code the inheritance is covered...

thank you for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 4:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i assume it is just a limitation of the annotation conversion. not every possible scenario is covered...you can help make this scenario covered with by at least reporting it in jira (patches even better)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 5:13 am 
Newbie

Joined: Sun Feb 05, 2006 6:24 pm
Posts: 7
jira... i haven't used this until now... i have done something with hibernates xml mapping, but just started to learn annotation based mapping configuration... so i'm far away to provide a patch... but i can write a jira issue and point to this thread...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 5:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yup - and attaching a *small* mapping file that illustrates what you want...and even better what output you would expect will be great

_________________
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.