-->
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.  [ 12 posts ] 
Author Message
 Post subject: hbm2java doesn't work well !
PostPosted: Tue Dec 09, 2003 9:31 am 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
I have read the document carefully.
And I tried two ways as follows to use hbm2java, but it doesn't work well.

1> My .bat file is as follows:
Code:
@echo off
rem hibernatePathset

set JDBC_DRIVER=D:\oracle\ora92\jdbc\lib\classes12.zip
set HIBERNATE_HOME=F:\hibernate-2-0-3
set LIB=%HIBERNATE_HOME%\lib
set PROPS=%HIBERNATE_HOME%\src
set CP=%JDBC_DRIVER%;%PROPS%;%HIBERNATE_HOME%\hibernate2.jar;%LIB%\commons-pool.jar;%LIB%\commons-dbcp.jar;%LIB%\commons-beanutils.jar;%LIB%\commons-logging.jar;%LIB%\commons-collections.jar;%LIB%\commons-lang.jar;%LIB%\cglib.jar;%LIB%\dom4j.jar;%LIB%\odmg.jar;%LIB%\jdom.jar;%LIB%\xml-apis.jar;%LIB%\xerces.jar;%LIB%\xalan.jar;C:\j2sdk1.4.1\lib;%PROPS%;%HIBERNATE_EX_HOME%\hibernate-tools.jar;%HIBERNATE_HOME%\hibernate2.jar;%HIBERNATE_HOME%\hibernate-tools.jar;%LIB%\commons-logging.jar;%LIB%\commons-collections.jar;%LIB%\commons-lang.jar;%LIB%\cglib.jar;%LIB%\dom4j.jar;%LIB%\odmg.jar;%LIB%\jdom.jar;%LIB%\xml-apis.jar;%LIB%\xerces.jar;%LIB%\xalan.jar;C:\j2sdk1.4.2_03\bin

The command and faults was showed as follows:
Code:
F:\hibernate-extensions-2-0-2\tools\bin>java -cp %CP% net.sf.hibernate.tool.hbm2java.CodeGenerator --output=c:\out c:\th\src\psrtype.hbm.xml
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/hibernate/tool/hbm2java/CodeGenerator

2> My another .bat file is as follows:
Code:
@echo off

rem -------------------------------------------------------------------
rem Setup environment for hibernate tools
rem -------------------------------------------------------------------

set JDBC_DRIVER=D:\oracle\ora92\jdbc\lib\classes12.zip
rem set JDBC_DRIVER=C:\Progra~1\SQLLIB\java\db2java.zip;C:\mm.mysql-2.0.14\mm.mysql-2.0.14-bin.jar
rem set HIBERNATE_HOME=..\..\hibernate-2.0
set HIBERNATE_HOME=F:\hibernate-2-0-3

set CORELIB=%HIBERNATE_HOME%\lib
set LIB=..\lib
set PROPS=%HIBERNATE_HOME%\src
set CP=%JDBC_DRIVER%;%PROPS%;%HIBERNATE_HOME%\hibernate2.jar;%CORELIB%\commons-logging.jar;%CORELIB%\commons-collections.jar;%CORELIB%\commons-lang.jar;%CORELIB%\cglib.jar;%CORELIB%\dom4j.jar;%CORELIB%\odmg.jar;%CORELIB%\xml-apis.jar;%CORELIB%\xerces.jar;%CORELIB%\xalan.jar;%LIB%\jdom.jar

The command and faults was showed as follows:
Code:
F:\hibernate-extensions-2-0-2\tools\bin>hbm2java.bat c:\th\src\psrtype.hbm.xml
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/hibernate/MappingException


I am mad at the "hbm2java" thing!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 11:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does
%HIBERNATE_HOME%\hibernate2.jar
really exists ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 12:20 pm 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
Setting up batch files it is easy to miss a jar file or something. I would modify your batch file to add jar files in various directories so you don't have to keep modifying your batch files. Add something like:

set CLASSPATH=
for %%i in (C:\projects\examples\lib\*.jar) do set CLASSPATH=!CLASSPATH!;%1 %%i
echo %CLASSPATH%

In this case you will have to run cmd.exe with the /V option to allowed delayed execution (to set the !CLASSPATH! within the for loop).

Some IDEs also support running Java code. In Eclipse I use the run option to generate .hbm files and then generate beans.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You can also use the hbm2java task.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 6:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The tools presentation we did for JAOO has examples of using hbm2java using the ant task.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 8:56 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
max wrote:
You can also use the hbm2java task.

where can I find some examples of hbm2java task?
BTW: The url links about jaoo examples as David said is invalid now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 9:00 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
dmmorris wrote:
Setting up batch files it is easy to miss a jar file or something. I would modify your batch file to add jar files in various directories so you don't have to keep modifying your batch files. Add something like:

set CLASSPATH=
for %%i in (C:\projects\examples\lib\*.jar) do set CLASSPATH=!CLASSPATH!;%1 %%i
echo %CLASSPATH%

In this case you will have to run cmd.exe with the /V option to allowed delayed execution (to set the !CLASSPATH! within the for loop).

Some IDEs also support running Java code. In Eclipse I use the run option to generate .hbm files and then generate beans.

I'm afraid that your explaination is not very clear to me.
Would you mind explaining your advise in another way? Thank you.


Top
 Profile  
 
 Post subject: seems to be missing jars in your classpath
PostPosted: Tue Dec 09, 2003 9:25 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I agree that the messages which say you are missing the class net.sf.hibernate.MappingException mean your hibernate2.jar isn't being found. Your path of %HIBERNATE_HOME%\hibernate2.jar (F:\hibernate-2-0-3 \hibernate2.jar) doesn't seem to exist (per the error messages).

On another note, my stand-alone test on a Windows machine requires a two jars you didn't include in your classpath:

commons-beanutils.jar (a utility jar)
jta.jar (required for transactions)

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 2:22 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
The main point I was trying to get across is that if you rely on batch files that have to be changed with every release the maintenance will cause tend to cause problems at the worst possible times. Once you get this sort of thing set up your goal should be that it runs on auto-pilot without intervention even when you update your system. You can either make the batch file more flexible or use a better tool. I use Eclispse and have run definitions set up for the various tools that I can run at will to generate new hbm files and entity beans.

Using ant is another option, and I frequently use ant to automate repetitive tasks. What ever you use, it is best if it doesn't break when you get updates and continues to work after receiving the inevitable updates to Hibernate.

You can use a for loop in a .bat file to add all jar files in a particular directory to your classpath. That is much less prone to keying errors and will help your .bat file to work when you update to newer/different jar files. Older versions of the dos command shell set environment variables once but the /V option with environment variables enclosed in exclamation marks (!) accomplishes the same thing. You could also set up a different .bat file to append to an environment variable an call that in the for loop but neither of these options is as reliable as the alternatives.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 10:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
ffeliza wrote:
where can I find some examples of hbm2java task?
BTW: The url links about jaoo examples as David said is invalid now.


Try the download section of the tools links at this URL
http://hibernate.bluemars.net/159.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 8:59 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
david wrote:
ffeliza wrote:
where can I find some examples of hbm2java task?
BTW: The url links about jaoo examples as David said is invalid now.


Try the download section of the tools links at this URL
http://hibernate.bluemars.net/159.html

thank you.
it does work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 10:21 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
aha !!
I solved my problem!
ok, my solution goes as follows:
1> setEnvironment.bat
Code:
@echo off

rem -------------------------------------------------------------------
rem Setup environment for hibernate tools
rem -------------------------------------------------------------------

set JDBC_DRIVER=D:\oracle\ora92\jdbc\lib\classes12.zip
set HIBERNATE_HOME=F:\hibernate-2-0-3

set CORELIB=%HIBERNATE_HOME%\lib
set LIB=..\lib
set PROPS=%HIBERNATE_HOME%\src
set CP=%PROPS%;%HIBERNATE_HOME%\hibernate2.jar;%LIB%\ant.jar;%LIB%\c3p0.jar;%LIB%\commons-pool.jar;%LIB%\commons-dbcp.jar;%LIB%\commons-beanutils.jar;%LIB%\commons-logging.jar;%LIB%\commons-collections.jar;%LIB%\commons-lang.jar;%LIB%\cglib-asm.jar;%LIB%\connector.jar;%LIB%\dom4j.jar;%LIB%\odmg.jar;%LIB%\jdom.jar;%LIB%\xml-apis.jar;%LIB%\xerces.jar;%LIB%\xalan.jar;C:\j2sdk1.4.2_03\lib;C:\j2sdk1.4.2_03\bin;%JDBC_DRIVER%
set CLASSPATH=for %%i in (F:\http\workshop_toolset_java\lib\*.jar) do set CLASSPATH=!CLASSPATH!;%1 %%i

2> build.xml (modified based on the "build.xml" in Hibernate Workshop Toolset Package)
Code:

    <property name="src.dir" location="src"/>
    <property name="gensrc.dir" location="gensrc"/>
    <property name="build.dir" location="classes"/>

    <path id="libs">
        <fileset dir="lib">
            <include name="**/*.jar"/>
            <include name="**/*.zip"/>
        </fileset>
    </path>

    <taskdef name="hbm2java"
        classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
        classpathref="libs"/>

    <target name="bottomup.hbm2java"
        description="Generate .java from .hbm files.">

        <hbm2java config="${build.dir}/hibernate.cfg.xml"
            output="${gensrc.dir}">

            <fileset dir="${gensrc.dir}">
                <include name="**/PSRType.hbm.xml"/>
            </fileset>
        </hbm2java>

    </target>

3> what dmmorris advised is the most important thing to solve my problem. Since I only know a little about how to write .bat files on Windows OS, the "set CLASSPATH= for %%i in (C:\projects\examples\lib\*.jar) do set CLASSPATH=!CLASSPATH!;%1 %%i" sentence helped me a lot. And I believe I must omit some Jar in my former classpath. All goes very well after I added dmmorris's sentense into my setEnvironment.bat.
The url link gaved by david also helped me to edit my own build.xml file.

You are so generous and warm-hearted guys. Thank you !


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