-->
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.  [ 3 posts ] 
Author Message
 Post subject: Persistent class not found
PostPosted: Sat Sep 25, 2004 8:57 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Here is my build.xml file. It can generate a 'classes' folder with the .class and .hbm.xml file in it but the schema export still cannot find the persistent class. I have read all the posts on classpath and now I'm getting a little irritated on why my build.xml file won't run Schema Export. As of right now my build file if I have sql code manually on a txt file, it can create the tables if i do "ant create-tables" . However I still need to get my Schema-Export tool working to create the sql script to even create the tables.

Here is my build.xml file:

<?xml version="1.0"?>

<project name="test" default="compile" 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"/>
<property name="src.java.dir" location="${source.root}/java"/>

<property name="blah" value="airline"/>
<property name="database.userid" value="root"/>
<property name="database.password" value="password"/>
<property name="database.url" value="jdbc:mysql://localhost/test"/>
<property name="database.driver" value="com.mysql.jdbc.Driver"/>
<property name="database.driver.file" value="${lib.dir}/mysql-connector-java-3.0.14-production-bin.jar"/>
<property name="database.driver.classpath" value="${database.driver.file}"/>
<property name="database.schema" value=""/>
<property name="database.catalog" value=""/>
<property name="database.script.file" value="${source.root}/sql/${blah}-mysql.sql"/>

<property environment="env" />


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

<pathelement location="${env.CLASSPATH}"/>
</path>




<!-- Teach Ant how to use Hibernate's code generation tool -->
<taskdef name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="project.class.path"/>

<!-- Generate the java code for all mapping files in our source tree -->
<target name="codegen"
description="Generate Java source from the O/R mapping files">
<hbm2java output="${source.root}">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>


<!-- 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>
<path refid="project.class.path"/>
<pathelement location="${class.root}"/>
</classpath>
</javac>
</target>


<target
name="create-tables"
description="Create tables"
>
<echo>Creating tables using URL ${database.url}</echo>
<sql
classpath="${database.driver.classpath}"
driver="${database.driver}"
url="${database.url}"
userid="${database.userid}"
password="${database.password}"
src="${database.script.file}"
/>
</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>



I get the error:

MappingExceptionError: no persistent class found.

Why is that? When I run 'codegen' it will create a java file based off it's respective hbm.xml file. However when I run 'schema' I get that error.
What could be the soln or any suggestions?


Top
 Profile  
 
 Post subject: Same Problem
PostPosted: Sun Sep 26, 2004 9:42 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
I am having the same problem.

Here is my definition for the SchemaExportTask.

Code:
   <target name="db-schema" depends="hibernate-mappings" description="Generates a DB schema file from the hibernate class mapping files.">
      <echo message="starting..." />
      <taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="project.class.path">
         <classpath>
            <!--
            <fileset dir="${build.classes.dir}">
               <include name="**/*.class" />
               <include name="**/*.properties" />
            </fileset>
            -->
            <fileset dir="/dev/games/lib">
               <include name="hibernate2.jar" />
               <include name="commons-logging.jar" />
               <include name="commons-collections-3.1.jar" />
            </fileset>
            <fileset dir="/dev/games/lib/build">
               <include name="dom4j-1.5.jar" />
            </fileset>

         </classpath>
      </taskdef>

      <schemaexport properties="${build.classes.dir}/hibernate.properties" delimiter=";" drop="false" output="schema.sql" quiet="false" text="true">
         <fileset dir="${build.dir}">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>

   </target>


I've tried the following, with no success.

1. Including the compiled classes in the classpath definition within the taskdef.
2. Added a "path" element defining "project.class.path" within my properties settings, then using that value in the taskdef under attribute "classpathref".

Here is the actual error:

Code:
db-schema:
     [echo] starting...
[schemaexport] Sep 26, 2004 7:34:51 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: Hibernate 2.1.2
[schemaexport] Sep 26, 2004 7:34:51 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: hibernate.properties not found
[schemaexport] Sep 26, 2004 7:34:51 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: using CGLIB reflection optimizer
[schemaexport] Sep 26, 2004 7:34:51 PM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] INFO: Mapping file: C:\dev\games\build\classes\p2p\common\ExceptionLog.hbm.xml
[schemaexport] Sep 26, 2004 7:34:51 PM net.sf.hibernate.cfg.Configuration add
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [p2p.common.ExceptionLog] not found


The ExceptionLog class is definitely there, as is it's cute little .hbm.xml file.

Any help would be appreciated.

Lukas


Top
 Profile  
 
 Post subject: Solved, for me at least.
PostPosted: Mon Sep 27, 2004 8:59 am 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
This is a cross-post, please forgive.

Okay, I finally got it to work, and I think the reason it wasn't working is pretty crappy.

My task was defined as such. Before, I was trying to define classpaths within the task using filesets, but nothing worked. So, because everyone else was doing it, I switched to using the "classpathred" attribute in the taskdef element.

Code:
   <target name="db-schema" description="Generates a DB schema file from the hibernate class mapping files.">
      <taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
         classpathref="project.class.path">
      </taskdef>
      <schemaexport properties="${build.classes.dir}/hibernate.properties" delimiter=";"
         drop="false" output="schema.sql" quiet="false" text="true">
         <fileset dir="${build.classes.dir}">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>
   </target>


Before, when things were not working, my path definition looked like this. It found the jar files wonderfully, but not the classes or the properties file.

Code:
         <path id="project.class.path">
            <fileset dir="${build.classes.dir}">
               <include name="**/*.class" />
               <include name="hibernate.properties" />
            </fileset>
            <fileset dir="/dev/games/lib">
               <include name="hibernate2.jar" />
               <include name="commons-logging.jar" />
               <include name="commons-collections-3.1.jar" />
            </fileset>
            <fileset dir="/dev/games/lib/build">
               <include name="dom4j-1.5.jar" />
            </fileset>
            
         </path>


When a "pathelement" variable was added to the path, everything works dandy now.

Code:
         <path id="project.class.path">
            <pathelement location="${build.classes.dir}"/>
      
            <fileset dir="/dev/games/lib">
               <include name="hibernate2.jar" />
               <include name="commons-logging.jar" />
               <include name="commons-collections-3.1.jar" />
            </fileset>
            <fileset dir="/dev/games/lib/build">
               <include name="dom4j-1.5.jar" />
            </fileset>
            
         </path>


And I feel strangely... unsatisfied.

Lukas


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