-->
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.  [ 8 posts ] 
Author Message
 Post subject: Do not process Composite-ID classes (hbmtemplate)
PostPosted: Thu May 31, 2007 10:57 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hello,

I am using hbmtemplate to generate DAOs from entities. A problem raises when I use the ANT task below: Not only entities, but also composite ids inside them are being processed.

Finally my template produces DAOs for entities AND composite ids. But DAOs for composite ids make no sense at all.

How do I set up hbmtemplate or my freemarker-template to ignore composite id classes while processing?

Code:
         <!-- Generate Daos -->
         <hbmtemplate
            filepattern="dao/{class-name}DaoImpl.java"
            templatepath="${buildconfig}"
            template="dao.ftl">
         </hbmtemplate>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 2:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
in b9 the trick is to check if something is a component and then just bail out so no content is generated (and the file would not be generated)

in lateer version (svn) you can set foreach on the hbmtempalte to:

configuration - generate a single file with a $cfg variable

entity - generate a file per entity

component - generate a file per component

...and these can be comma seperated to control what you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 4:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
in b9 the trick is to check if something is a component and then just bail out so no content is generated (and the file would not be generated)

in lateer version (svn) you can set foreach on the hbmtempalte to:

configuration - generate a single file with a $cfg variable

entity - generate a file per entity

component - generate a file per component

...and these can be comma seperated to control what you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 6:19 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Is b9 a version number?

I tried to use foreach="entity" within the hbmtemplate but it did not work. I guess I would have to use the latest svn version. But I do not like to use development releases.

Code:
                 <hbmtemplate
                    templatepath="${templates}"
                    template="${spring.daos.template}"
                    destdir="${webinf}"
                    filepattern="${context-daos.xml}"
                    foreach="entity">
                 </hbmtemplate>


What about thoe other way to bail out if the current component is NOT an entity? From where do I bail out? From within the freemarker template would be too late wouldnt it? I assume the file is generated at this point already. So how do I bail out from within the hbmtemplate tag?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 6:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
do a conditional if on isComponent
Code:
<#if !c2j.isCompnent(pojo)>
blahblah
</#if>


if the generated content is empty after a call to .trim() we don't generate a file.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 7:24 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Code:
[hibernatetool] Method public boolean org.hibernate.tool.hbm2x.Cfg2JavaTool.isComponent(org.hibernate.mapping.Property) threw an exception when invoked on org.hibernate.tool.hbm2x.Cfg2JavaTool@1878144
[hibernatetool] The problematic instruction:
[hibernatetool] ----------
[hibernatetool] ==> if !c2j.isComponent(pojo) [on line 1, column 1 in spring-daos.ftl]


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


Throws an exception for me :(

Code:
freemarker.template.TemplateModelException: Method public boolean org.hibernate.tool.hbm2x.Cfg2JavaTool.isComponent(org.hibernate.mapping.Property) threw an exception when invoked on org.hibernate.tool.hbm2x.Cfg2JavaTool@1878144


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 7:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
grrrr...i suck.

!pojo.isComponent()


the c2j method is for properties.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 7:59 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
No, you don't suck! You help me out :)

Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.