-->
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.  [ 4 posts ] 
Author Message
 Post subject: Adding an instance to Hibernate Freemarker template model
PostPosted: Tue Jan 11, 2011 1:22 pm 
Newbie

Joined: Tue Jan 11, 2011 1:10 pm
Posts: 3
I'm using hbm2java to generate some code from my hbm definitions.

I've written a custom freemarker template, however I need to call some java code and return the value to the template. Think of it as calling a string manipulation library from freemarker. I know this is possible since cfg2JavaTool allows it. I am using the hibernate3-maven-plugin.

How would I add a class of my own to the freemarker template model?


Top
 Profile  
 
 Post subject: Re: Adding an instance to Hibernate Freemarker template model
PostPosted: Wed Jan 12, 2011 7:20 am 
Newbie

Joined: Tue Jan 11, 2011 1:10 pm
Posts: 3
Sorry I'm not quite following you. Using the hibernate3-maven-plugin I assume I can set the classpath up by setting the classpath as so (ignoring my other plugin details):

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<componentProperties>
<classpath>someClassPath</classpath>
<myPropName>someString</myPropName>
</componentProperties>
</configuration>
</plugin>

But how would I then reference my class in side the freemarker template? ${com.mypackage.Class} doesn't seem to work.

I know I can access myPropName in my template. Is it possible to make myPropName a class/instance reference instead?


Top
 Profile  
 
 Post subject: Re: Adding an instance to Hibernate Freemarker template model
PostPosted: Wed Jan 12, 2011 8:16 am 
Newbie

Joined: Tue Jan 11, 2011 1:10 pm
Posts: 3
After digging in the Hibernate Tool source code I found what I needed to do:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<componentProperties>
<classpath>someClassPath</classpath>
<hibernatetool.myPropName.toolclass>com.myPackage.myClass</hibernatetool.myPropName.toolclass>
</componentProperties>
</configuration>
</plugin>

The prefix "hibernatetool." and suffix ".toolclass" are identifiers to tell the AbstractExporter class to create an instance out of the FQCN. I couldn't see this documented anywhere after a few days of searching, which is rather frustrating.

So now I can use {$myPropName.someInstanceMethod()} to return the value from my class.


Top
 Profile  
 
 Post subject: Re: Adding an instance to Hibernate Freemarker template model
PostPosted: Tue Jan 18, 2011 8:51 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Matt.Lloyd101, this is documented here
http://docs.jboss.org/tools/2.1.0.Beta1 ... ml#d0e3308


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