-->
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.  [ 10 posts ] 
Author Message
 Post subject: adding custom exporters to eclipse hibernate tools codegen
PostPosted: Thu Mar 15, 2007 8:38 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
I installed hibernate tools eclipse plugin recently, so I have one question about it:

How can I add another DAO exporter. I want to use two exporters for dao , each using it's own template.

thanx!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 9:13 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Use Ant to generate your code using two <hbmtemplate> tasks. Here is an old piece of my build (I don't generate DAO's anymore, use base class and Spring to configure specific entity DAO's). Hope this gives you a place to start.

Code:
   <!-- ================================================================
       target: dao
         The target to generate the DAO interface and implementation
         classes. note that the hibernate configuration file must
         have already been generated/supplied
       ================================================================ -->
   <target name="dao" depends="init" description="Generate the DAO interface and implementation classes">
      <echo message="***** Building the DAO interface and implementation files... *****"/>
      <hibernatetool>
         <configuration configurationfile="${dir.javasource}/hibernate.cfg.xml"/>
         <hbmtemplate
            templatepath="${dir.template.dao}"
            template="${dao.intf.templatename}"
            destdir="${dir.dest.dao.interface}"
            filepattern="${dao.intf.filepattern}">
            <propertyset refid="dao.properties"/>
         </hbmtemplate>
         <hbmtemplate
            templatepath="${dir.template.dao}"
            template="${dao.hibernate.templatename}"
            destdir="${dir.dest.dao.hibernate}"
            filepattern="${dao.hibernate.filepattern}">
            <propertyset refid="dao.properties"/>
         </hbmtemplate>
      </hibernatetool>
      <sequential>
         <echo message="***** ...DAO interface and implementation files sucessfully generated, refreshing... *****"/>
         <antcall target="refresh"/>
         <echo message="***** ...DAO interface and implementation file generation complete! *****"/>
      </sequential>
    </target>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 7:52 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
Thanx, I configured ant task and it works, but it throws exception:
Interesting thing is that code is generateed successfully. I don't understand why exception is thrown

Here is the stack:
Code:
[hibernatetool] freemarker.core.InvalidReferenceException: Expression clazz.entityName is undefined on line 38, column 74 in daohome.ftl.
[hibernatetool] at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
[hibernatetool] at freemarker.core.Expression.getStringValue(Expression.java:118)
[hibernatetool] at freemarker.core.Expression.getStringValue(Expression.java:93)
[hibernatetool] at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
[hibernatetool] at freemarker.core.Environment.visit(Environment.java:196)
[hibernatetool] at freemarker.core.MixedContent.accept(MixedContent.java:92)
[hibernatetool] at freemarker.core.Environment.visit(Environment.java:196)
[hibernatetool] at freemarker.core.Environment.visit(Environment.java:233)
[hibernatetool] at freemarker.core.BlockAssignment.accept(BlockAssignment.java:83)
[hibernatetool] at freemarker.core.Environment.visit(Environment.java:196)
[hibernatetool] at freemarker.core.MixedContent.accept(MixedContent.java:92)
[hibernatetool] at freemarker.core.Environment.visit(Environment.java:196)
[hibernatetool] at freemarker.core.Environment.process(Environment.java:176)
[hibernatetool] at freemarker.template.Template.process(Template.java:231)
[hibernatetool] at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:245)
[hibernatetool] at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplateProducer.java:67)
[hibernatetool] at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
[hibernatetool] at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:97)
[hibernatetool] at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:84)
[hibernatetool] at org.hibernate.tool.hbm2x.GenericExporter.exportComponent(GenericExporter.java:69)
[hibernatetool] at org.hibernate.tool.hbm2x.GenericExporter.exportClasses(GenericExporter.java:63)
[hibernatetool] at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:41)
[hibernatetool] at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
[hibernatetool] at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
[hibernatetool] at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:364)
[hibernatetool] at org.apache.tools.ant.Target.execute(Target.java:341)
[hibernatetool] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hibernatetool] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[hibernatetool] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[hibernatetool] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
[hibernatetool] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] An exception occurred while running exporter #2:generic exporter
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
[hibernatetool] freemarker.core.InvalidReferenceException: Expression clazz.entityName is undefined on line 38, column 74 in daohome.ftl.

BUILD FAILED
/home/igor/projekti/Wily/build.xml:30: org.hibernate.tool.hbm2x.ExporterException: Error while processing
template daohome.ftl


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:08 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
I can't figure out how you can have a PersistentClass without an entityName. That's an odd one. Do you have any non-straightforward mappings, i.e. Component, Subclassing?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:10 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
Yes, I have subclassing. You think this could be the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:16 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Definitely could be. I've had problems with my inheritance mappings (table-per-class-hierarchy) in the reverse engineering tools, and usually map my subclasses by hand.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:44 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
Thanx, you helped me a lot.
I will ignore this exception for now, since code is generated properly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 11:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
don't ignore it; it will stop any subsequent code generation - it's probably caused by you calling entityName on something that is a component (not an entity).

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 11:58 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
But, how can I solve this.
I think it fails on one-to-many or many-to-one mappings.

here is the mapping on which this exception occures:

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 default-lazy="false">

   <class name="hr.ib.webframework.site.Page" table="ib_page">

      <id name="id" type="java.lang.Long">
         <column name="ib_id" not-null="true" />
         <generator class="native" />
      </id>

      <property name="title" type="string" column="ib_title" length="255" not-null="false" />
      <property name="keywords" type="string" column="ib_keywords" length="1000" not-null="false" />
      <property name="description" type="string" column="description" length="1000" not-null="false" />
      <property name="url" type="string" length="255" not-null="true" />
      <property name="view" type="string" column="ib_view" length="255" not-null="false" lazy="false" />

      <many-to-one name="parent" class="hr.ib.webframework.site.Page" column="ib_parentpage" not-null="false" />

      <list name="children" cascade="all" lazy="true">
         <key column="ib_parentpage" />
         <index column="ib_index" />
         <one-to-many class="hr.ib.webframework.site.Page" />
      </list>

      <list name="modules" cascade="all" lazy="true">
         <key column="ib_page_id" />
         <index column="ib_index" />
         <one-to-many class="hr.ib.webframework.site.modules.BasicModule" />
      </list>


   </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
can't see anything wrong as such ;(

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