-->
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.  [ 5 posts ] 
Author Message
 Post subject: Converting annotation configuration to .hbm
PostPosted: Thu Mar 23, 2006 7:27 pm 
Newbie

Joined: Fri Mar 17, 2006 7:08 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate Tools 3.1.0.beta4
hibernate-annotations-3.1beta8
Hibernate 3.1

I am trying to reverse engineer an annotation configuration into a set of .hbm files using the hbm2hbmxml exporter in hibernate tools.

The results are a set of invalid .hbm files which don't validation against the DTD's. It seems that the many-to-one declarations and various other attributes seem to not get generated..

For example:

Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 23/03/2006 22:59:49 by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
    <class name="com.dytech.pems.model.claim.ClaimType" table="ClaimType">
        <id name="id" type="java.lang.Long">
            <column name="id" />
            <generator class="native"></generator>
        </id>
        <property name="historicalId" type="java.lang.Long" update="false">
            <column name="historicalId" />
        </property>
        <set name="budgetTypes" inverse="false">
            <key>
                <column name="ClaimType_id" not-null="true" />
            </key>
        </set>
    </class>
</hibernate-mapping>


The interesting thing is that if I run the schema export to the database all the tables etc, get generated as we expect. I then use the jdbcconfiguration and get something that is fairly close to what I wanted with the correct mappings and all the missing attributes getting generated.

The documentation suggests that you can use any type of configuration and convert to .hbm files.

ant task:
Code:
<hibernatetool destdir="${build.dir}/hbmTemp">
      <classpath >
             <pathelement location="${classes.dir}"/>
                <path refid="hibernate.tools.classpath" />
          </classpath>
          <annotationconfiguration configurationfile="${config.dir}/hibernate.cfg.xml"/>
          <hbm2hbmxml/>
       </hibernatetool>

hibernate config:
Code:
<session-factory>
      <property name="connection.url">jdbc:jtds:sqlserver://eris:1433/dev</property>
      <property name="connection.username">username</property>
      <property name="connection.password">password</property>

      <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
      <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
       <property name="hibernate.show_sql">true</property>
       <property name="hibernate.hbm2ddl.auto">create</property>

    <mapping class="model.budget.BudgetType" />
... etc
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 10:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, this is the intention and we do it for basic cases.

But we don't support all cases and probably won't unless someone starts contributes things that are missing or at least open up good bug reports on them (good in the sense with minimal failing test cases and not hundres of huge annotated classes with a comment saying: it does not work ;)

So, the best thing you can do is enhance the hbm2hbmxml templates
the second best is make some good reports.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Slight improvement in hbm2hbmxml
PostPosted: Sat Jun 03, 2006 3:36 pm 
Newbie

Joined: Fri Sep 26, 2003 11:44 am
Posts: 13
Hi,

I am using linguine maps to create diagrams from annotated classes. I changed the bag.hbm.ftl to handle one-to-many relationships similar to set.hbm.ftl.

New bag.hbm.ftl:

Code:
        <bag
      name="${property.name}"
        inverse="${property.value.inverse?string}"
   >
        <key>
           <#foreach column in property.value.key.columnIterator>
             <#include "column.hbm.ftl">
           </#foreach>
        </key>

        <#if c2h.isOneToMany(property)>
        <one-to-many
     class="${property.getValue().getElement().getAssociatedClass().getClassName()}"/>
        <#else>
          <element type="string" column="dummy"/>
   </#if>
     </bag>
     


Old bag.hbm.ftl:

Code:
        <bag
      name="${property.name}"
        inverse="${property.value.inverse?string}"
   >
        <key>
           <#foreach column in property.value.key.columnIterator>
             <#include "column.hbm.ftl">
           </#foreach>
        </key>

        <element type="string" column="dummy"/>
     </bag>
     


Very slight improvment, but enough to get a nicer looking diagram.

Regards,

Ali

_________________
Ali Ibrahim


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 03, 2006 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi Ali,

Please put this in jira, much appreciated.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Created JIRA issue
PostPosted: Mon Jun 05, 2006 3:49 pm 
Newbie

Joined: Fri Sep 26, 2003 11:44 am
Posts: 13
Hi,

I created a JIRA issue with my ad-hoc patch:

http://opensource.atlassian.com/project ... se/HBX-683

Thanks for all your hard work on such a great tool!

Regards,

Ali

_________________
Ali Ibrahim


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