-->
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: classpath problem with annotated hbm2java
PostPosted: Tue Sep 20, 2005 10:06 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
org.hibernate.MappingException: Unable to load class declared as <mapping class="Category"/> in the configuration:

Maybe this is obvious but I can't get it working as I#m not so firm with ant. Can anyone tell me what is wrong with mit ant target or give me a working example for hbm2ddl with an annotationconfiguration ?

<hibernate-configuration>
<session-factory>
<mapping package="com.ina.pls.model"/>
<mapping class ="Category"/>
</session-factory>
</hibernate-configuration>

Ant buildfile:
<project name="fls_tools" default="db.ddl2file">
<property name="src" value="." />
<property name="build" value="./classes" />
<property name="lib.dir" value="lib" />

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

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

<target name="db.ddl2file" description="Export the schema DDL to SQL text file in build directory">
<hibernatetool destdir=".">
<annotationconfiguration propertyfile="hibernate.properties" configurationfile="hibernate.cfg.xml">
</annotationconfiguration>
<hbm2ddl export="false" console="true" drop="false" create="true" outputfilename="test.ddl" delimiter=";" />
</hibernatetool>
</target>

</project>


Hibernate version:
3.1beta
hibernate-tools3.1alpha5

Mapping documents:
annotated class
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
C:\Users\kratztho\workspace\com.ina.pls.model2\build.xml:28: org.hibernate.MappingException: Unable to load class declared as <mapping class="Category"/> in the configuration:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you probably just need to put the class in the classpath of the ant task.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:06 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
http://forum.hibernate.org/viewtopic.php?t=945581

has the same problem. I'll give it a try without ant using SchemaExport for now, cause building from cvs is timely not a real option for now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the forum post you refer to there is already fixed in the alpha5 release.

have you tried to add the classpath with your model classes to the actual call to <hibernatetool> where it belongs ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:34 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
thats what I tried now (sorry ant syntax is quite horrible to me), doesn`t work either.
When I call SchemaExport from code everything is fine.
Thank you for your patience.
Thomas

<target name="hbm2ddl" description="Export the schema DDL to SQL text file in build directory">
<hibernatetool destdir=".">
<annotationconfiguration propertyfile="hibernate.properties" configurationfile="hibernate.cfg.xml">
<fileset dir="${build}" id="id">
<include name="**/*.class"/>
</fileset>
</annotationconfiguration>
<hbm2ddl export="false" console="true" drop="false" create="true" outputfilename="test.ddl" delimiter=";" />
<!--hbm2java generics="true" /-->
</hibernatetool>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
could you please run with ant -verbose and show the full stacktrace ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:44 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
OK. Here it comes.

[hibernatetool] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.

BUILD FAILED
/home/thomas/workspace/eiswind.paris.model/build.xml:26: org.hibernate.MappingException: Unable to load class declared as <mapping class="eiswind.paris.model.Category.java"/> in the configuration:
at org.apache.tools.ant.Task.perform(Task.java:373)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: org.hibernate.MappingException: Unable to load class declared as <mapping class="eiswind.paris.model.Category.java"/> in the configuration:
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:380)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1376)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1357)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1333)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1287)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:50)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2DDLGeneratorTask.execute(Hbm2DDLGeneratorTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
... 8 more
Caused by: java.lang.ClassNotFoundException: eiswind.paris.model.Category.java
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1149)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1090)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:960)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:377)
... 19 more
--- Nested Exception ---
org.hibernate.MappingException: Unable to load class declared as <mapping class="eiswind.paris.model.Category.java"/> in the configuration:
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:380)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1376)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1357)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1333)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1287)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:50)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2DDLGeneratorTask.execute(Hbm2DDLGeneratorTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: java.lang.ClassNotFoundException: eiswind.paris.model.Category.java
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1149)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1090)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:960)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:377)
... 19 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<mapping class="eiswind.paris.model.Category.java"/>

.java ?!!

That is not the classname is it ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 3:19 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
I knew it(me) must be STUPID. Appreciate your help!!

but now I get a new exception... :/
Invalid character in XML PArsing when reading a classfile ?

is there something ill character in my hibernate.cfg.xml maybe?

as said everything is fine

BUILD FAILED
/home/thomas/workspace/eiswind.paris.model/build.xml:26: Failed in building configuration when adding /home/thomas/workspace/eiswind.paris.model/classes/eiswind/paris/model/Category.class
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:112)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTask.java:91)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:77)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:50)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:150)
at org.hibernate.tool.ant.Hbm2DDLGeneratorTask.execute(Hbm2DDLGeneratorTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:115)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: org.hibernate.MappingException: Could not read mapping document from file: /home/thomas/workspace/eiswind.paris.model/classes/eiswind/paris/model/Category.class
at org.hibernate.cfg.Configuration.addFile(Configuration.java:262)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:108)
... 16 more
Caused by: org.hibernate.MappingException: Could not parse mapping document in input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:421)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:259)
... 17 more
Caused by: org.dom4j.DocumentException: Invalid byte 2 of 2-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence.
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:412)
... 18 more
--- Nested Exception ---


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 4:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm...please show your cfg.xml

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 12:07 pm 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
looks good to me, but I remember the .java thing :) ...

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="parisSessionFactory">
<mapping class="eiswind.paris.model.Category"/>
</session-factory>
</hibernate-configuration>

hibernate.properties
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql:paris
hibernate.connection.username=thomas
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=5
hibernate.c3p0.timeout=300
hibernate.c3p0.max_statements=50
hibernate.c3p0.idle_test_period=3000


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is your ant task...it is adding *.class files via the fileset - only hbm.xml files should be added that way.

your class is also already being included in the mapping in the hibernate.cfg.xml so even if it worked it would result in duplicate imports.

_________________
Max
Don't forget to rate


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.