-->
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.  [ 15 posts ] 
Author Message
 Post subject: Generate DAO interface and implementation classes
PostPosted: Tue Nov 01, 2005 4:28 am 
Newbie

Joined: Fri Oct 28, 2005 11:33 am
Posts: 13
I would like to generate a DAO interface and implementation class through hibernate tools, for example

interface CustomerDAO
and
class CustomerDAOHibernate

As it seems, the default installation would generate only the DAO implementation class and that one can be customized through vm-templates. How would I tell it to create more?

Furthermore, I have read an (old) posting that changing the file name seems to be difficult. What's state of the art today?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 6:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
all possible - look for <hbmtemplate>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Where can I get more information on hbmtemplate
PostPosted: Tue Nov 08, 2005 1:04 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
I have googled hbmtemplate and searched for this on this site and only found three posts that I had difficulty following.

I would like to generate custom daos and interfaces. I modified daohome.vm inside of plugins to generate myself a (Table)Home.java class which has both of my classes in it and then im cutting and pasting out of home into two seperate files with appropriate class names. Not pretty but Im not sure how else to do it. I have been doing this via eclipse.

I believe that I need to put hibernate-tools.jar into ant home and then use hbmtemplate somehow with my own custom template.

Thanks in advance for any help.

_________________
-RS


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
currently the docs for hbmtemplate is in the jira, the forum but probably most uptodate in the current cvs.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Got hbmtemplate working but receiving an error
PostPosted: Tue Nov 08, 2005 8:47 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
Using Hibernate 3 with Hiberante tools 3.1 beta1
Here is my ant task

<target name="gendao" description="Generate DAO files from hbm.xml">

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/>

<!-- basicly this appears to ignore the classpathrefelement & classpath="${librarydir}" -->
<hibernatetool>
<classpath>
<pathelement path="${classpath}"/>
<path refid="classpath"/>
<fileset dir="${librarydir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<configuration configurationfile="${src.dir}/hibernate2.cfg.xml" >
<fileset dir="${gensrc.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<!-- <hbm2dao destdir="${gensrc.dir}" templatepath="${templates.dir}"/> -->

<hbmtemplate
destdir="gensrc"
template="templates/dao/customdao.vm"
filepattern="com/cms/ds/hibernate/{class-name}DAOHibernate.java"/>

</hibernatetool>
</target >


Note that for some reason this task does not pick up the classpath, I had to source the necessary jars into classpath in a seperate environment variables.sh file. Im not sure why this wouldn't work. In any case this runs and creates the customdao files however at the end it throws an error and I'm not sure why, it has created the custom files.

/urs2/jdev3/CMSHibernate/build.xml:202: org.hibernate.tool.hbm2x.ExporterException: MethodInvocationException while processing template templates/dao/customdao.vm. Invocation of method 'getJavaTypeName' in class org.hibernate.tool.hbm2x.Cfg2JavaTool threw exception class java.lang.NullPointerException : null

Like I said this created the custom file from the template. I saw naother post but thought I would show how I configured ant here to get it to work and mention this in case someone else looks for it , not sure if I m not getting something right or this is a bug.

_________________
-RS


Top
 Profile  
 
 Post subject: I think this may be an off by one error
PostPosted: Tue Nov 08, 2005 8:52 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
I havent looked into the source code for all this stuff, but this feels an awful lot like an off by one error because it actually does generate the files for every mapping that is specified.

Method getJavaTypeName threw exception for reference $c2j in template templates/dao/customdaointerface.vm at [18,58]
[hibernatetool] - Method getJavaTypeName threw exception for reference $pojo in template templates/dao/customdaointerface.vm at [18,40]

BUILD FAILED
/urs2/jdev3/CMSHibernate/build.xml:175: org.hibernate.tool.hbm2x.ExporterException: MethodInvocationException while processing template templates/dao/customdaointerface.vm. Invocation of method 'getJavaTypeName' in class org.hibernate.tool.hbm2x.Cfg2JavaTool threw exception class java.lang.NullPointerException : null

_________________
-RS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It is probably because you have some constructs in your mapping file that haven't been tested or developed with the daohome templates.

If you can try with a nightly build or even better the CVS to verify if it have not already been fixed. (and report a case in jira if it hasn't)

I'm more concerned about the classloading issues you have. Could you elaborate some more on them ? Please remember that all the hibernate related jars must be in the <taskdef> and the classpath for the tool is *just* the jars that is relevant for your usertypes, mapping files etc. Don't put hibernate jars redundantly there again.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: I have these classpaths set up correctly I believe ....
PostPosted: Wed Nov 09, 2005 12:39 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
Thanks for all your help and feedback.

Here is my ant task.

As I have tried to configure based on your last suggestion, however It is still not set up correct.

My directory structure is very standard.

project dir
--build.xml
--lib
----hibernate3.jar
----and other hibernate required jars
--gensrc
----package structure
------hbm.xml files
------generated persistent classes and id classes

Here is my ant task and you can see that Im just trying to include the jars in the lib directory (totally standard), but I must not have this task set up correctly.

<target name="gendaoint" description="Generate DAO interface files from hbm.xml">

<!-- basicly this appears to ignore the classpath element -->

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath>
<pathelement path="${classpath}"/>
<path refid="classpath"/>
<fileset dir="${librarydir}">
<include name="**/*.jar"/>
</fileset>
</classpath>

</taskdef>

<!-- basicly this appears to ignore the classpath element as well-->
<hibernatetool>
<classpath>
<pathelement path="${classpath}"/>
<path refid="classpath"/>
<fileset dir="${librarydir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<configuration configurationfile="${src.dir}/hibernate2.cfg.xml" >
<fileset dir="gensrc">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>

<hbmtemplate
destdir="gensrc"
template="templates/dao/customdaointerface.vm"
filepattern="com/cms/ds/hibernate/{class-name}DAO.java"/>
</hibernatetool>
</target >

I have set up the classpath in the taskdef and in both the hibernate tool definition however I get the error

[root@comcms CMSHibernate]# ant gendaoint
Buildfile: build.xml

gendaoint:

BUILD FAILED
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

I then source a .sh file which looks like the folllowing and it works without the no class def found.

export HIB_HOME="/usr2/jdev3/CMSHibernate"
export HIB_LIB=$HIB_HOME/lib
export HIB_CLASSPATH=$HIB_LIB/antlr-2.7.5H3.jar:$HIB_LIB/asm-attrs.jar:$HIB_LIB/
asm.jar:$HIB_LIB/axis.jar:$HIB_LIB/cglib-2.1.jar:$HIB_LIB/commons-collections-2.
1.1.jar:$HIB_LIB/commons-discovery-0.2.jar:$HIB_LIB/commons-lang.jar:$HIB_LIB/co
mmons-logging-1.0.4.jar:$HIB_LIB/dom4j-1.6.jar:$HIB_LIB/ehcache-1.1.jar:$HIB_LIB
/hibernate3.jar:$HIB_LIB/hibernate-tools.jar:$HIB_LIB/hibernate-tools-orig.jar:$
HIB_LIB/jta.jar:$HIB_LIB/jtidy-r8-21122004.jar:$HIB_LIB/log4j-1.2.9.jar:$HIB_LIB
/mysql-connector-java-3.1.10-bin.jar:$HIB_LIB/velocity-1.4.jar:$HIB_LIB/velocity
-tools-generic-1.1.jar
export CLASSPATH=$CLASSPATH:$HIB_CLASSPATH

Again I'm only trying to include the jars in lib directory

_________________
-RS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 1:22 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
This may be a stupid question, but are you sure ${librarydir} is resolving properly? (Run ant -verbose to check). The classpath within the hibernatetool task shouldn't matter. I have a setup working off of the mainline in CVS that is fine. Here is how I have declared the task:

Code:
    <taskdef name="hibernatetool"
     classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/>


And invoke the tool:

Code:
       <hibernatetool destdir="${core.build.src.dir}">
           <configuration>
               <fileset dir="${core.model.dir}">
                   <include name="core/hbm/**.hbm.xml"/>
               </fileset>
               <fileset dir="${core.model.dir}">
                 <include name="**/hbm/**.hbm.xml"/>
                 <exclude name="core/hbm/**.hbm.xml"/>
               </fileset>
           </configuration>
           <hbm2java/>
       </hibernatetool>


Note how the classpath element isn't required -at all- in the <hibernatetool> task.


Top
 Profile  
 
 Post subject: Alright I echoed out the classpath ....
PostPosted: Wed Nov 09, 2005 2:27 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
So here is the updated ant task

Code:
   <target name="gendaoint" description="Generate DAO interface files from hbm.xml">
   <echo message="Here is the library directory ${librarydir}"/>   
   <property name="classpath.prop" refid="classpath"/>
   <echo message="Classpath is ${classpath.prop}"/>
   <!-- basicly this appears to ignore the classpath element -->   
   <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/>
      <hibernatetool>
         <configuration configurationfile="${src.dir}/hibernate2.cfg.xml" >
            <fileset dir="gensrc">
               <include name="**/*.hbm.xml" />
            </fileset>
         </configuration>
      
             <hbmtemplate
            destdir="gensrc"
            template="templates/dao/customdaointerface.vm"
            filepattern="com/cms/ds/hibernate/{class-name}DAO.java"/>
      </hibernatetool>
   </target >




I echoed the classpath in which I can see the hibernate3.jar where the missing class is from the error ..

Get ready for huge classpath output string....
Code:
[root@comcms CMSHibernate]# ant gendaoint
Buildfile: build.xml

gendaoint:
     [echo] Here is the library directory /urs2/jdev3/CMSHibernate/lib
     [echo] Classpath is /urs2/jdev3/CMSHibernate/lib/antlr-2.7.5H3.jar:/urs2/jdev3/CMSHibernate/lib/asm-attrs.jar:/urs2/jdev3/CMSHibernate/lib/asm.jar:/urs2/jdev3/CMSHibernate/lib/axis.jar:/urs2/jdev3/CMSHibernate/lib/cglib-2.1.jar:/urs2/jdev3/CMSHibernate/lib/commons-collections-2.1.1.jar:/urs2/jdev3/CMSHibernate/lib/commons-discovery-0.2.jar:/urs2/jdev3/CMSHibernate/lib/commons-lang.jar:/urs2/jdev3/CMSHibernate/lib/commons-logging-1.0.4.jar:/urs2/jdev3/CMSHibernate/lib/dom4j-1.6.jar:/urs2/jdev3/CMSHibernate/lib/ehcache-1.1.jar:/urs2/jdev3/CMSHibernate/lib/hibernate-tools-orig.jar:/urs2/jdev3/CMSHibernate/lib/hibernate-tools.jar:/urs2/jdev3/CMSHibernate/lib/hibernate3.jar:/urs2/jdev3/CMSHibernate/lib/jta.jar:/urs2/jdev3/CMSHibernate/lib/jtidy-r8-21122004.jar:/urs2/jdev3/CMSHibernate/lib/log4j-1.2.9.jar:/urs2/jdev3/CMSHibernate/lib/mysql-connector-java-3.1.10-bin.jar:/urs2/jdev3/CMSHibernate/lib/velocity-1.4.jar:/urs2/jdev3/CMSHibernate/lib/velocity-tools-generic-1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/BroadsoftOSSFullJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/BroadsoftOSSHandler.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSCommon.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSHibernate.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSOSSJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/SubscriberServiceRequestJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/antlr-2.7.5H3.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/asm-attrs.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/asm.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/axis-ant.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/axis.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/cglib-2.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-collections-2.1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-discovery-0.2.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-lang.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-logging-1.0.4.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/dom4j-1.6.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/ehcache-1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/hibernate3.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jax-qname.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-api.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-impl.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-libs.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-xjc.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxrpc.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jta.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/log4j-1.2.8.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/log4j-1.2.9.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/namespace.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/relaxngDatatype.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/saaj.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/wsdl4j-1.5.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/xsdlib.jar:/usr/local/jakarta-tomcat/common/classes:/usr/local/jakarta-tomcat/common/lib/activation.jar:/usr/local/jakarta-tomcat/common/lib/commons-el.jar:/usr/local/jakarta-tomcat/common/lib/jasper-compiler-jdt.jar:/usr/local/jakarta-tomcat/common/lib/jasper-compiler.jar:/usr/local/jakarta-tomcat/common/lib/jasper-runtime.jar:/usr/local/jakarta-tomcat/common/lib/jsp-api.jar:/usr/local/jakarta-tomcat/common/lib/mysql-connector-java-3.1.10-bin.jar:/usr/local/jakarta-tomcat/common/lib/naming-factory-dbcp.jar:/usr/local/jakarta-tomcat/common/lib/naming-factory.jar:/usr/local/jakarta-tomcat/common/lib/naming-resources.jar:/usr/local/jakarta-tomcat/common/lib/servlet-api.jar:/usr/local/jakarta-tomcat/shared/classes:/usr/local/jakarta-tomcat/shared/lib/jstl.jar:/usr/local/jakarta-tomcat/shared/lib/standard.jar

BUILD FAILED
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

Total time: 4 seconds



It looks like the task wont pick up the defined classpath unless its on the environment classpath, which Im setting with a .sh file manually.

_________________
-RS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:10 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Um, typo?

/urs2 instead of /usr2 in your prior post.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:11 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
If that's not it, you also have a couple different jar files containing hibernate and hibernate tools on the classpath. What you've posted looks like it should work. What version of ant are you using?


Top
 Profile  
 
 Post subject: For some reason my ant is messing up the basedir
PostPosted: Wed Nov 09, 2005 4:50 pm 
Newbie

Joined: Mon Nov 07, 2005 1:27 pm
Posts: 6
I am using
[root@comcms CMSHibernate]# ant -version
Apache Ant version 1.6.3 compiled on April 28 2005

Good catch but actually both urs2 and usr2 on my system point to the same place (symlinked dont ask me !) so this isnt the issue even when I change the project definition
from
<project name="CMSHibernate" default="compile" basedir=".">
to
<project name="CMSHibernate" default="compile" basedir="/usr2/jdev3/CMSHibernate">

Then the path typo is corrected but it still doesnt work here is the output without the misspelled basedir ( which I still dont know why this is coming up)

[root@comcms CMSHibernate]# ant gendaoint
Buildfile: build.xml

gendaoint:
[echo] This is the basedir /usr2/jdev3/CMSHibernate
[echo] Here is the library directory /usr2/jdev3/CMSHibernate/lib
[echo] Classpath is /usr2/jdev3/CMSHibernate/lib/antlr-2.7.5H3.jar:/usr2/jdev3/CMSHibernate/lib/asm-attrs.jar:/usr2/jdev3/CMSHibernate/lib/asm.jar:/usr2/jdev3/CMSHibernate/lib/axis.jar:/usr2/jdev3/CMSHibernate/lib/cglib-2.1.jar:/usr2/jdev3/CMSHibernate/lib/commons-collections-2.1.1.jar:/usr2/jdev3/CMSHibernate/lib/commons-discovery-0.2.jar:/usr2/jdev3/CMSHibernate/lib/commons-lang.jar:/usr2/jdev3/CMSHibernate/lib/commons-logging-1.0.4.jar:/usr2/jdev3/CMSHibernate/lib/dom4j-1.6.jar:/usr2/jdev3/CMSHibernate/lib/ehcache-1.1.jar:/usr2/jdev3/CMSHibernate/lib/hibernate-tools-orig.jar:/usr2/jdev3/CMSHibernate/lib/hibernate-tools.jar:/usr2/jdev3/CMSHibernate/lib/hibernate3.jar:/usr2/jdev3/CMSHibernate/lib/jta.jar:/usr2/jdev3/CMSHibernate/lib/jtidy-r8-21122004.jar:/usr2/jdev3/CMSHibernate/lib/log4j-1.2.9.jar:/usr2/jdev3/CMSHibernate/lib/mysql-connector-java-3.1.10-bin.jar:/usr2/jdev3/CMSHibernate/lib/velocity-1.4.jar:/usr2/jdev3/CMSHibernate/lib/velocity-tools-generic-1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/BroadsoftOSSFullJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/BroadsoftOSSHandler.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSCommon.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSHibernate.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/CMSOSSJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/SubscriberServiceRequestJAXB.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/antlr-2.7.5H3.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/asm-attrs.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/asm.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/axis-ant.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/axis.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/cglib-2.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-collections-2.1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-discovery-0.2.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-lang.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/commons-logging-1.0.4.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/dom4j-1.6.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/ehcache-1.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/hibernate3.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jax-qname.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-api.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-impl.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-libs.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxb-xjc.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jaxrpc.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/jta.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/log4j-1.2.8.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/log4j-1.2.9.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/namespace.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/relaxngDatatype.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/saaj.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/wsdl4j-1.5.1.jar:/usr/local/jakarta-tomcat/webapps/axis/WEB-INF/lib/xsdlib.jar:/usr/local/jakarta-tomcat/common/classes:/usr/local/jakarta-tomcat/common/lib/activation.jar:/usr/local/jakarta-tomcat/common/lib/commons-el.jar:/usr/local/jakarta-tomcat/common/lib/jasper-compiler-jdt.jar:/usr/local/jakarta-tomcat/common/lib/jasper-compiler.jar:/usr/local/jakarta-tomcat/common/lib/jasper-runtime.jar:/usr/local/jakarta-tomcat/common/lib/jsp-api.jar:/usr/local/jakarta-tomcat/common/lib/mysql-connector-java-3.1.10-bin.jar:/usr/local/jakarta-tomcat/common/lib/naming-factory-dbcp.jar:/usr/local/jakarta-tomcat/common/lib/naming-factory.jar:/usr/local/jakarta-tomcat/common/lib/naming-resources.jar:/usr/local/jakarta-tomcat/common/lib/servlet-api.jar:/usr/local/jakarta-tomcat/shared/classes:/usr/local/jakarta-tomcat/shared/lib/jstl.jar:/usr/local/jakarta-tomcat/shared/lib/standard.jar

BUILD FAILED
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

And I know ive got hibnerate tools in ant home /lib and in the current project lib, still this should work as you said, but its Still giving me the classnotfound wihtout sourcing the variables.

_________________
-RS


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 5:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have multiple versions of the same jars on your classpath - never a good thing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: ant script to generate java 5.0 DAOs for hibernate
PostPosted: Wed Nov 09, 2005 6:33 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 8:41 pm
Posts: 47
Here is an XSLT and ant script I've wrote to generate DAOs from hibernate mapping files. I use it as a quick and dirty solution and hope soon there will
be support in hibernate tools to do same using velocity templates.

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:str="http://exslt.org/strings"
   extension-element-prefixes="str">
   <xsl:output method="text" />
   <xsl:param name="genDAOlong">net.sf.jbprize.framework.dao.hibernate.GenericHibernateDAO</xsl:param>
   <xsl:param name="genDAO">GenericHibernateDAO</xsl:param>
   <xsl:template match="/hibernate-mapping">
      <xsl:for-each select="class">
          <xsl:variable name="class">
          <xsl:for-each select="str:tokenize(@name, '.')">
            <xsl:if test="position() = last()">
              <xsl:value-of select="."/>
            </xsl:if>
          </xsl:for-each>
          </xsl:variable>
          <xsl:variable name="idClass">
          <xsl:for-each select="str:tokenize(id/@type|composite-id/@class, '.')">
            <xsl:if test="position() = last()">
              <xsl:choose>
                <xsl:when test=". = 'long'">
                  <xsl:value-of select="'Long'"/>
                </xsl:when>
                <xsl:when test=". = 'string'">
                  <xsl:value-of select="'String'"/>
                </xsl:when>
                <xsl:when test=". = 'big_decimal'">
                  <xsl:value-of select="'BigDecimal'"/>
                </xsl:when>
                <xsl:when test=". = 'integer'">
                  <xsl:value-of select="'Integer'"/>
                </xsl:when>
                <xsl:when test=". = 'character'">
                  <xsl:value-of select="'Character'"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="."/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:if>
          </xsl:for-each>
          </xsl:variable>
          <xsl:variable name="idClassFull">
            <xsl:choose>
              <xsl:when test="id/@type|composite-id/@class = 'long'">
                <xsl:value-of select="'java.lang.Long'"/>
              </xsl:when>
              <xsl:when test="id/@type|composite-id/@class = 'string'">
                <xsl:value-of select="'java.lang.String'"/>
              </xsl:when>
              <xsl:when test="id/@type|composite-id/@class = 'big_decimal'">
                <xsl:value-of select="'java.math.BigDecimal'"/>
              </xsl:when>
              <xsl:when test="id/@type|composite-id/@class = 'integer'">
                <xsl:value-of select="'java.lang.Integer'"/>
              </xsl:when>
              <xsl:when test="id/@type|composite-id/@class = 'character'">
                <xsl:value-of select="'java.lang.Character'"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="id/@type|composite-id/@class"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <xsl:variable name="package">
          <xsl:for-each select="str:tokenize(@name, '.')">
            <xsl:if test="position() != last()">
              <xsl:value-of select="."/>
              <xsl:if test="position() != (last() - 1)">
                <xsl:value-of select="'.'"/>
                </xsl:if>
            </xsl:if>
          </xsl:for-each>
          </xsl:variable>
          <xsl:value-of select="concat('package ', $package, ';')"/>
           <xsl:value-of select="' '" />
           <xsl:value-of select="' '" />
           <xsl:value-of select="concat('import ', $genDAOlong, ';')"/>
           <xsl:value-of select="' '" />
           <xsl:value-of select="concat('import ', @name, ';')"/>
           <xsl:value-of select="' '" />
           <xsl:value-of select="concat('import ', $idClassFull, ';')"/>
           <xsl:value-of select="' '" />
           <xsl:value-of select="' '" />
         <xsl:value-of
            select="concat('public class ', $class, 'DAO')" />
         <xsl:value-of select="' '" />
         <xsl:value-of
            select="concat('  extends ', $genDAO, '&lt;', $class, ', ', $idClass, '&gt; {')" />
         <xsl:value-of select="' '" />
         <xsl:value-of select="concat('  public ', $class, 'DAO() {')" />
         <xsl:value-of select="' '" />
         <xsl:value-of
            select="concat('    super(', $class, '.class, ', $idClass, '.class);')" />
         <xsl:value-of select="' '" />
         <xsl:value-of select="'  }'" />
         <xsl:value-of select="' '" />
         <xsl:value-of select="'}'" />
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>


Ant script

Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="DAO Generator" default="daogen">
   <property name="my.root.dir"         value="${basedir}" />
   <property name="src.dir"             value="${basedir}/src" />
   <property name="build.common"        value="${basedir}/build"/>
   <property name="build.thirdparty"    value="${basedir}/../ThirdParty"/>
   <!-- Build classpath -->
   <path id="classpath">
      <pathelement location="${basedir}" />
      <fileset dir="${build.thirdparty}/lib/xerces-xalan">
         <include name="xalan.jar" />
         <include name="xml-apis.jar" />
         <include name="xercesImpl.jar" />
         <include name="resolver.jar" />
      </fileset>
   </path>
   <property name="build.classpath" refid="classpath" />
   <target name="daogen" description="Generate DAO java source code from hibernate mappings">
      <fileset dir="${src.dir}" id="hbm-files">
         <include name="**/*.hbm.xml" />
      </fileset>
      <xmlcatalog id="catalog">
         <dtd publicId="-//Hibernate/Hibernate Mapping DTD 3.0//EN" location="${basedir}/dtd/hibernate-mapping-3.0.dtd" />
      </xmlcatalog>
      <style basedir="${src.dir}" destdir="${src.dir}" force="true" scanincludeddirectories="true" processor="trax" style="${basedir}/xslt/dao-gen/DaoGen.xsl" classpathref="classpath">
         <factory name="org.apache.xalan.processor.TransformerFactoryImpl">
            <attribute name="http://xml.apache.org/xalan/features/optimize" value="true" />
         </factory>
         <xmlcatalog refid="catalog" />
         <mapper type="glob" from="*.hbm.xml" to="*DAO.java" />
      </style>
   </target>
</project>


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