-->
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.  [ 7 posts ] 
Author Message
 Post subject: hbmtemplate daohome.ftl problems when using a composite-id
PostPosted: Wed Dec 13, 2006 6:21 am 
Newbie

Joined: Tue Dec 05, 2006 8:36 am
Posts: 7
Hello,

the problem of this post is similar to http://forum.hibernate.org/viewtopic.php?t=967519, but I guess I have found the reason of the problem (though no solution yet ...)

Hibernate-Tools version: 3.2-beta8

The problem is that invoking hbmtemlate with the daohome.ftl from hibernate-tools causes an error when using a composite-id. It seems like hbmtemplate tries to create DAO classes for the composite-id classes, but fails on the undefined clazz.hasNaturalId() and clazz.entityName. (I found out the latter when removing the code for generating the findByNaturalId method from the daohome.ftl).

Is there a way to get hbmtemplate work in such a setting? I don't really know how Freemarker works and how the clazz.hasNaturalId() and clazz.entityName are affected by a mapping document, so unfortunately I'm completely helpless at this point. I've posted the error, a sample hibernate mapping document and my Ant task below. hbm2java works, but the hbmtemplate task fails.

Best Regards,
Matthias


Here's the error:


Code:
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing template dao/daohome.ftl
[hibernatetool] freemarker.core.InvalidReferenceException: Expression clazz.hasNaturalId is undefined on line 161, column 6 in dao/daohome.ftl.



And here's an example hibernate mapping file that should cause the error with clazz.hasNaturalId(). It simply contains a composite-id with 2 key properties.


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 28.11.2006 15:30:24 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
    <class name="eg.hibernate.CacertT" table="CACERT_T" lazy="false">
        <composite-id name="Id" class="eg.hibernate.CacertTPK">
            <key-property name="CacertIssuerId" type="java.lang.Long">
                <column name="CACERT_ISSUER_ID" />
            </key-property>
            <key-property name="CacertSerialNumber" type="java.lang.Long">
                <column name="CACERT_SERIAL_NUMBER" />
            </key-property>
        </composite-id>

    </class>
</hibernate-mapping>




for hbmtemplate I've placed all relevant folders from the hibernate-tools.jar in a hiberatetemplates folder. My Ant task looks like this:

Code:
      <hibernatetool destdir="${project.source.directory}" templatepath="${basedir}/${etc.dir}/hibernatetemplates/">
        <classpath>
          <path refid="project.run.classpath" />
          <path location="${project.source.directory}" />
        </classpath>

        <configuration configurationfile="${etc.dir}/hibernate.cfg.xml" />

        <hbm2java jdk5="true" />

        <hbmtemplate templatepath="${basedir}/${etc.dir}/hibernatetemplates/" template="dao/daohome.ftl">
          <property key="jdk5" value="true" />
          <property key="ejb3" value="false" />
        </hbmtemplate>

      </hibernatetool>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 11:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, hbmtemplate process both components and entities.

using <dao2hbm> will only run entities.

if that is not ok for you then do a test in the beginning on the $pojo to see if it is an entity or component and simply stop rendering so the result will an empty string.

and yes, I need to somehow add a flag to hbmtemplate to make it configurable what it should actually process.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 12:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, hbmtemplate process both components and entities.

using <dao2hbm> will only run entities.

if that is not ok for you then do a test in the beginning on the $pojo to see if it is an entity or component and simply stop rendering so the result will an empty string.

and yes, I need to somehow add a flag to hbmtemplate to make it configurable what it should actually process.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:27 pm 
Newbie

Joined: Tue Dec 05, 2006 8:36 am
Posts: 7
Thank you very much!

My current solution is to put the content of the existing daohome.ftl inside the following:

Code:
<#if !pojo.isComponent()>
...
</#if>


Now it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 5:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
p.s. in SVN we now have <hbmtemplate ... foreach="entity"/> where foreach states what kind of thing you want to iterate over (it can be a comma seperated list of "configuration", "component" and "entity").

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 6:27 am 
Newbie

Joined: Tue Dec 05, 2006 8:36 am
Posts: 7
Great, thanks, definitely a better way than my tentative workaround.

So I guess this will find its way to the beta9?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 6:57 am 
Hibernate Team
Hibernate Team

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

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