-->
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.  [ 33 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: need help for build.xml [Ant newbie]
PostPosted: Sat Sep 04, 2004 10:57 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
I have read pretty much all the posts on the Mapping Exception Error: No persistent class found. Everyone keeps on saying classpath, but I believe my classpath is correct. Do I need to include something in my environment variable classpath?

Here is my build.xml file:

<?xml version="1.0"?>
<project name="test" default="db" basedir=".">
<!-- Set up properties containing important project directories -->
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="lib.dir" value="lib"/>
<property name="data.dir" value="data"/>

<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include our own classes, of course -->
<pathelement location="${class.root}" />
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>


<!-- Create our runtime subdirectories and copy resources into them -->
<target name="prepare" description="Sets up build structures">
<mkdir dir="${class.root}"/>

<!-- Copy our property files and O/R mappings for use at runtime -->
<copy todir="${class.root}" >
<fileset dir="${source.root}" >
<include name="**/*.properties"/>
<include name="**/*.hbm.xml"/>
</fileset>
</copy>
</target>

<!-- Compile the java source of the project -->
<target name="compile" depends="prepare"
description="Compiles all Java classes">
<javac srcdir="${source.root}"
destdir="${class.root}"
debug="on"
optimize="off"
deprecation="on"
classpathref="project.class.path">
<classpath refid="project.class.path"/>
</javac>
</target>


<target name="schema" depends="compile"
description="Generate DB schema from the O/R mapping files">
<!-- Teach Ant how to use Hibernate's schema generation tool -->
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<path refid="project.class.path"/>
<pathelement location="${class.root}"/>
</classpath>
</taskdef>

<schemaexport properties="${class.root}/hibernate.properties"
quiet="no" text="no" drop="no" delimiter=";" output="schema-export.sql">
<fileset dir="${class.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>


</project>

No matter what I change, I get the error net.sf.hibernate.MappingException: persistent class [Wassup] not found.

What is the error? Because in my classes folder that is created when compiled, there is a Wassup.class and Wassup.hbm.xml file.
My classpath looks pretty good after reading all the posts I thought.

Any help appreciated,

John


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 05, 2004 11:16 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Anohter question:

I saw some build files that had this line:

<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport" fork="true">

how can you have this without a Main method?
Becsue I would get a noClassDef found error when I use it.
Also my java classes are POJO so don't have a main method either.
So how would I use this line, or is it even needed?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 05, 2004 11:38 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
I aslo saw a post that the persistent classes need to be in a .jar format? Is that true, and if so how would I go about doing it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 12:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I recommend you direct these kinds of questions to an Ant-related list, or perhaps try the forums at javaranch.com. Good Luck.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 4:26 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
The last 2 questions are just thoughts on my part as to how to fix the problem of the Mappin Exception.

I would still like to know if my build file in the first part is a correct build file from creating tables through Schema Export tool.

Do you see any problems with it or do I need to make any changes? Or does it look good to you?

I don't want to do the things in the last 2 questoins I asked if I don't have to.


So looking at my build file as it is right now, is there any errors you can see, or does it look good to you?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 6:03 am 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
Check to see that Wassup.class and Wassup.hbm.xml are next to each other, in the same directory or resolve to be the same in the classpath:
com.blah.Wassup.class - com/blah/Wassup.class
com.blah.Wassup.hbm.xml - com/blah/Wassup.hbm.xml

With ant I generally copy the hbm.xml files over to the generated class directory so they're right next to each other when I jar them up -- or stick them in /WEB-INF/classes/com/blah/Wassup ... etc when I war them up.

Are you using XDoclet?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 2:56 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
I am not using XDoclet at the moment. Just Ant at the moment. In my hibernate-2.1 folder I created a practice folder with the files in src/com/blah/Wassup.java and src/com/blah/Wassup.hbm.xml . My build file creates a class folder with classes/com/blah/Wassup.class and classes/com/blah/Wassup.hbm.xml . Heh I didn't use my web-inf folder from tomcat 5.0.

So that is what is going on at the moment. Shouldn't that be what it is suppose to do?

Also, should I dl XDoclet AND Maven to do my build script? Do I have to, or with just Ant and Hibernate-2.1 I can use Schema Export?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 4:01 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
Maven has a hibernate plugin, but it only does schema-export and something called aggregate mapping.
Aggregate mapping is better done using XDoclet's hibernatedoclet hibernatecfg subtask.

You need to do a number of things to get Maven, and then get XDoclet, and then setup XDoclet to run under maven ...

If you're not as familiar with Ant as you'd like I'd suggest using it first. Here's a section from a build.xml I wrote to generate and update my database(s). I have cvs HEAD version of Hibernate, which occurs in a directory called Hibernate2. Buidling it creates a parallel directory.

Code:
 
....
      <path id="xdoclet.classpath">
        <fileset dir="${xdoclet.lib.home}">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <path id="hibernate.classpath">
        <fileset dir="${hibernate.src.lib.home}" includes="**/*.jar"/>
        <fileset dir="${hibernate.build.dir}" includes="**/*.jar"/>
    </path>
....
   <taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
      <classpath>
        <path refid="xdoclet.classpath"/>
        <path refid="hibernate.classpath"/>
      </classpath>
    </taskdef>
    <target name="hibernate" depends="prepare"
      description="Generates the *.hbm.xml files, as well as the hibernate.cfg.xml file">
      <hibernatedoclet
        destdir="${hibernatedoclet.dest.dir}"
        excludedtags="@version,@author,@todo"
        force="false"
        verbose="${hibernate.verbose}"
      >

        <fileset dir="${java.src.dir}">
          <include name="**/*.java"/>
        </fileset>

        <hibernate version="2.0"/>

        <hibernatecfg
          jdbcUrl="jdbc:mysql://192.168.0.5:3306/ccgdb?autoReconnect=true"
          dataSource="java:/comp/env/jdbc/ccgdb"
          dialect="net.sf.hibernate.dialect.MySQLDialect"
          driver="com.mysql.jdbc.Driver"
          useOuterJoin="true"
          userName="someuser"
          password="somepassword"
          showSql="true"
        >
        </hibernatecfg>
      </hibernatedoclet>

    </target>




    <target name="schemaexport" depends="compile"
      description="Generates SQL from our classes">

      <taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
        <classpath>
          <path refid="hibernate.classpath"/>
          <pathelement location="${build.classes.dir}"/>
          <pathelement location="${hibernatedoclet.dest.dir}"/>
        </classpath>
      </taskdef>
      <!--
              output="${build.dir}/schema-export.sql">
      -->
      <schemaexport
          properties="hibernate.connection.properties"
          quiet="${schemaquiet}"
          text="no"
          drop="no"
          delimiter=";">
          <fileset dir="${hibernatedoclet.dest.dir}">
              <include name="**/*.hbm.xml"/>
          </fileset>
      </schemaexport>
    </target>

    <target name="schemaupdate" depends="compile">
      <taskdef name="schemaupdate" classname="net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask">
        <classpath>
          <path refid="hibernate.classpath"/>
          <pathelement location="${build.classes.dir}"/>
          <pathelement location="${hibernatedoclet.dest.dir}"/>
        </classpath>
      </taskdef>
      <schemaupdate
          properties="${basedir}/hibernate.connection.properties"
        quiet="no">
          <fileset dir="${hibernatedoclet.dest.dir}">
              <include name="**/*.hbm.xml"/>
          </fileset>
      </schemaupdate>
    </target>


Note the section:
Quote:
Code:
      <taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
        <classpath>
          <path refid="hibernate.classpath"/>
          <pathelement location="${build.classes.dir}"/>
          <pathelement location="${hibernatedoclet.dest.dir}"/>
        </classpath>
      </taskdef>

That's how I make sure the *.hbm.xml and *.class files they map are "next" to each other.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 8:02 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
ok, quick questions about the properties part at the beginningof the build file.

So I dl the Xdoclet and unzipped it. I didn't add anything to my environment variable System classpath for the XDoclet.

So I basically included the XDoclet folder in my Practice folder.

so here is what I was thinking trying to conform your property settings to my settings.

So in my folder I called Practice, I have a folder called lib which I copied and pasted from hibernate-2.1, a folder called src which I copied and pasted from hibernate-2.1, an XDoclet folder which I unzipped directly from what I dl, and also the hibernate.properties file in the Practice folder and in the src folder.

project.class.path is same thing as your hibernate.classpath

<property name="class.root" value="classes"/> is same thing as your ${build.classes.dir}

<property name="src.root" value="src"/> is same thing as your ${src.dir}

<property name="lib.dir" value="lib"/> is same thing as your ${hibernate.src.lib}

<property name="xdoclet.lib.home" value="xdoclet/lib"/> is same thing as your ${xdoclet.lib.home}

<property name="class.root" value="classes"/> would be same thing also as your ${build.dir} since like the build directory is suppose to hold compiled classes anyway.

hibernate.properties would be same thing as your hibernate.connection.properties

Please correct me if I am off-based on my property tags.

Also I am confused as to what ${hibernatedoclet.dest.dir} refers to. Would I create my own folder called hibernatedoclet.dest? Or like make it ${src.root} ?


Also for your ${java.src.dir} do I have to create a java folder to hold my classes or is this like I don't need to do, because before I just put the java and hbm.xml files in the src folder.

Lastly, what does: dataSource="java:/comp/env/jdbc/ccgdb" refer to?


Sorry, I am a real newbie when it comes to this, and I am getting some error messages, so it would be extremely helpful if you could answer all my questions and correct me if my tags are wrong. Also, for XDoclet do I have to do anything to install it? Because so far I just put the XDoclet folder I got into my Practice folder.


Top
 Profile  
 
 Post subject: Re: need help for build.xml [Ant newbie]
PostPosted: Tue Sep 07, 2004 2:22 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
mush wrote:
No matter what I change, I get the error net.sf.hibernate.MappingException: persistent class [Wassup] not found.


Check if you have files src/Wassup.java and src/Wassup.hbm.xml. Also, when the build breaks, is there a file classes/Wassup.class. My guess is that you have the class in some package, but the Hibernate mapping has not mentioned the package.

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 3:08 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
i include the files inmy src folder, and in the ensuing classes folder that is created, even though the build breaks I c that the .class and .hbm.xml files r in there.

So like if I have a package called 'com'.
then i put the .java and .hbm.xml files in src/com and they have "package com;" as heading and also in hbm.xml file too.

in the classes folder that is created I have
classes/com folder with the .class files and .hbm.xml files in there.

So it seems to have everything there.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 8:10 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Hi John,

I am assuming that you are using Hibernate2. I looked up the Hibernate 2.1.4 sources, and the only place where a MappingException with such a message is thrown is from the bindClass() method of net.sf.hibernate.cfg.Binder class.

The Exception is thrown when Hibernate tries to load a class and it can't find that class. The full classname which Hibernate tried to load will be printed in the error message. From the error message that you had provided, it seems to me that Hibernate is looking for the class "Wassup" and it can't find the same. From your previous post it looks like your Wassup class is within some package.

So my guess is that you have informed Hibernate about a class "Wassup" in some mapping file, but your class is actually called "some.package.Wassup".

Are you sure that Wassup.hbm.xml has a package attribute in the <hibernate-mapping/> element?

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="your.package.name">
    <class name="Wassup" table="WASSUP_TABLE_NAME">
    <!-- ... -->
    </class>
</hibernate-mapping>

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 10:48 am 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
within your java sourc file Wassup.java, what is the package name? Let's assume:
package com.blah;

So assume your directory structure underneath your ant build.xml looks something like:

/yourroot
| -- build.xml
| -- project.properties
` -- hibernate.connection.properties
` -- src
` -- java
` -- blah
| -- Wassup.java
` -- SomethElse.java

Unless you specify otherwise, ant will assume that all builds will take place in yourroot/target. In your project.properties file set:
build.dir=target
build.classes.dir=${build.dir}/classes
<mkdir dir="${build.classes.dir}"/> (just to cover your butt)

when your ant file runs javac it will compile Wassup.java into:
/yourroot
`-- target
`-- classes
` --com
` -- blah
| -- Wassup.class
` -- SomethingElse.class

since I build a bunch of different things under target I separate the classes this way.

When you run your hibernatedoclet task it will create a similar directory structure based on your package declarations in Wassup.java.

hibernatedoclet.dest.dir=${build.dir}/xdoclet/hibernatedoclet
Is the setting I use. Since I'm also using other xdoclet tasks I subdivide them under target/xdoclet
You will have to <mkdir dir="${hibernatedoclet.dest.dir}"/> in some prepare task.

hibernatedoclet will then generate:

/yourroot
`-- target
`-- xdoclet
`-- hibernatedoclet
`-- com
`-- blah
| -- Wassup.hbm.xml
` -- SomethingElse.hbm.xml

Now you can also just set hiberndatedoclet.dest.dir to be:
hibernatedoclet.dest.dir=${build.classes.dir} and these files will be generated right next to the .class files they map. When hibernate loads up it doesn't need the .java files so much as it needs the .class files with the hbm.xml files.

As far as lifecyle is concerned, schema-export is a build time event, while the other things hibernate does are application-load events and runtime events. So you can specify a different hibernate.properties for this task than the one you end up stuffing into WEB-INF, WEB-INF/classes, or wherever the "class root" of your application is.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 11:17 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Not to go away from XDcolet but I have a deadline coming up so not sure have that much time to learn XDoclet, though after I think I can. If I already have the mapping hbm.xml files, and the POJO classes I don't need to use XDoclet right? So I can write a build file that creates tables without using XDoclet?

Also in resposne to the last reply, I did include the package name.

Like: here's an example of my mapping file, I tried to make it simple. So like my POJO is in the folder src/com/blah. So I did package com.blah:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.blah">

<class name="Collection" table="WASSUP">
<id name="collectionID" type="integer" column="COLLECTIONID" unsaved-value="0">
<generator class="increment">
</generator>
</id>

<property name="name" type="string"/>

<property name="targetID" type="integer"/>

<property name="parentID" type="integer"/>

</class>

</hibernate-mapping>

On top of my POJO, there's: ' package com.blah; '

So I included all the package stuff.

So I was thinking since XDoclet is a way to generate mapping files of type hbm.xml right, then if I already have the mapping files, then I should just be able to create the tables already, but I am still getting same error message with Mapping Exception. At this point b4 the deadline I was thinking just to write a build file to create the tables, and then later learn XDoclet.

Thx,
John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 12:16 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
actually i get the same error doing command line to like:
java net.sf.hibenate.tool.hbm2ddl.SchemaExport Wassup.hbm.xml when I am in that particular directory.

Same error being persistent class not found.

So not sure if that would have any bearing on the ant script that has same error.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 33 posts ]  Go to page 1, 2, 3  Next

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.