*
The moose likes Object Relational Mapping and the fly likes persistent class not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "persistent class not found" Watch "persistent class not found" New topic
Author

persistent class not found

Carlos A. Perez
Greenhorn

Joined: Apr 09, 2004
Posts: 27
Hi:

Im learning Hibernate and I have some problems exporting the schema to the database.

Im using Eclipse, HSQLDB

When i try to export the schema i got the following message:

Buildfile: D:\Codigo\Java\workspace\Hibernate\build.xml
prepare:
[copy] Copying 1 file to D:\Codigo\Java\workspace\Hibernate\bin
schema:
[schemaexport] log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.
BUILD FAILED: D:\Codigo\Java\workspace\Hibernate\build.xml:72: Schema text failed: net.sf.hibernate.MappingException: persistent class [com.oreilly.hh.Track] not found
Total time: 8 seconds

My directory structure is the following:
+Hibernate //Proyect in Eclipse
+src
+com
+oreilly
+hh
+bin
+com
+oreilly
+hh
+antHibernateFiles
-build.xml
-hibernate.properties
-log4j.properties

The build.xml file:
<?xml version="1.0"?>
<project name="Harnessing Hibernate: The Developer's Notebook" default="codegen"
basedir="D:/Codigo/Java/workspace/Hibernate">

<property name="source.dir" value="src/"/>
<property name="class.dir" value="bin/"/>
<property name="lib.dir" value="C:/eclipse/lib"/>
<property name="lib.dir2" value="C:/eclipse/lib"/>
<property name="data.dir" value="C:/hsqldb/lib"/>


<path id="project.class.path">
<pathelement location="${lib.dir2}"/>
<pathelement location="${lib.dir}"/>
<fileset dir="${lib.dir2}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="db" description="Runs HSQLDB database management UI against the database file">
<java classname="org.hsqldb.util.DatabaseManagerSwing" fork="yes">
<classpath refid="project.class.path"/>
<arg value="-driver"/>
<arg value="org.hsqldb.jdbcDriver"/>
<arg value="-url"/>
<arg value="jdbc:hsqldb:${data.dir}/music"/>
<arg value="-user"/>
<arg value="sa"/>
</java>
</target>

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

<target name="codegen" description="Generate code for all mappings in our source tree">
<hbm2java output="${source.dir}">
<fileset dir="${source.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>

<target name="prepare">
<copy todir="${class.dir}">
<fileset dir="antHibernateFiles">
<include name="**/*.properties"/>
</fileset>
<fileset dir="${source.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</copy>
</target>



<target name="schema" depends="prepare"
description="Generate DB Schema from the O/R Mapping files">

<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>

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

</project>

The hibernate.properties file:

hibernate.dialect=net.sf.hibernate.dialectHSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:C:/hsqldb/data/music
hibernate.connection.username=sa
hibernate.connection.password=

The log4j.properties file:

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=info, stdout

log4j.logger.net.sf.hibernate=info

### log just the SQL
log4j.logger.net.sf.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=info

### log schema export/update ###
log4j.logger.net.sf.hibernate.tool.hbm2ddl=debug

### log cache activity ###
log4j.logger.net.sf.hibernate.cache=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace

I have tried changing the *.properties and build.xml to Hibernate, src and bin directories but it still doesnt work, i cant explain why but its strange because the target "codegen" works perfectly but not the target "schema", i have also try running Ant from console (i usually run ant inside Eclipse).

Thanks
Carlos A. Perez
Greenhorn

Joined: Apr 09, 2004
Posts: 27
sorry for the directory stucture
i repeat it:

Hibernate //project dir
Hibernate/bin
Hibernate/bin/com/oreilly/hh
Hibernate/src/com/oreilly/hh
Hibernate/antHibernateFiles

inside Hibernate/bin/com/oreilly/hh and Hibernate/src/com/oreilly/hh is the file Track.hbm.xml

and inside Hibernate/antHibernateFiles are build.xml, hibernate.properties, loj4j.properties
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
inside Hibernate/bin/com/oreilly/hh and Hibernate/src/com/oreilly/hh is the file Track.hbm.xml

along with Track.class?
i say this because of:
net.sf.hibernate.MappingException: persistent class [com.oreilly.hh.Track] not found


java amateur
Carlos A. Perez
Greenhorn

Joined: Apr 09, 2004
Posts: 27
yes the hbm.xml file its there.
I have found the problem, in the build.xml file in the path tag i was missing to include all the *.class files.



its strange because the file in the book doesnt need to include it and i have take a look to the errata from the author and lectors and nobody has said something about this error, maybe its the ant or hibernate versions.

Thanks
Carlos A. Perez
Greenhorn

Joined: Apr 09, 2004
Posts: 27
now i have another problem the log file doesnt appear anywhere

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: persistent class not found
 
Similar Threads
creating .hbm.xml file
Problem using Hibernate Extensions: hbm2java
Schema text failed: Dialect class not found
problem at using hibernate extension to build *java from *.hbm.xml
Classpath problems(?)