-->
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.  [ 9 posts ] 
Author Message
 Post subject: MappingException: unmapped class
PostPosted: Tue Apr 05, 2005 1:27 pm 
Newbie

Joined: Mon Mar 14, 2005 12:06 pm
Posts: 6
Hibernate version: 3.0 final

Eclipse version: 3.1.0

Mapping document: Track

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

<hibernate-mapping>

<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliott (with help from Hibernate)
</meta>

<id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<property name="title" type="string">
<meta attribute="use-in-tostring">true</meta>
<column name="TITLE" not-null="true" index="TRACK_TITLE"/>
</property>

<property name="filePath" type="string" not-null="true"/>

<property name="playTime" type="time">
<meta attribute="field-description">Playing time</meta>
</property>

<set name="artists" table="TRACK_ARTISTS">
<key column="TRACK_ID"/>
<many-to-many class="com.oreilly.hh.Artist" column="ARTIST_ID"/>
</set>

<set name="comments" table="TRACK_COMMENTS">
<key column="TRACK_ID"/>
<element column="COMMENT" type="string"/>
</set>

<property name="added" type="date">
<meta attribute="field-description">When the track was created</meta>
</property>

<property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>

</class>

<query name="com.oreilly.hh.tracksNoLongerThan">
<![CDATA[
from com.oreilly.hh.Track as track
where track.playTime <= :length
]]>
</query>

</hibernate-mapping>

Mapping document: Artist

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

<hibernate-mapping>

<class name="com.oreilly.hh.Artist" table="ARTIST">
<meta attribute="class-description">
Represents an artist who is associated with a track or album.
@author Jim Elliott (with help from Hibernate)
</meta>

<id name="id" type="int" column="ARTIST_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<property name="name" type="string">
<meta attribute="use-in-tostring">true</meta>
<column name="NAME" not-null="true" unique="true" index="ARTIST_NAME"/>
</property>

<set name="tracks" table="TRACK_ARTISTS" inverse="true">
<meta attribute="field-description">Tracks by this artist</meta>
<key column="ARTIST_ID"/>
<many-to-many class="com.oreilly.hh.Track" column="TRACK_ID"/>
</set>

</class>

<query name="com.oreilly.hh.artistByName">
<![CDATA[
from com.oreilly.hh.Artist as artist
where upper(artist.name) = upper(:name)
]]>
</query>

</hibernate-mapping>

ant script:

<?xml version="1.0"?>
<project name="Harnessing Hibernate: The Developer's Notebook"
default="db" basedir=".">

<!-- Set up properties containing important project directories -->
<property name="source.root" value="src"/>
<property name="class.root" value="bin"/>
<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>

<target name="db" description="Runs HSQLDB database management UI
against the database file--use when application is not running">
<java classname="org.hsqldb.util.DatabaseManager"
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>

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

<!-- Generate the java code for all mapping files in our source tree -->
<target name="codegen" depends="prepare"
description="Generate Java source from the O/R mapping files">
<hbm2java output="${source.root}">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
<eclipse.refreshLocal resource="hibernate.music/src" depth="infinite"/>
</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>
<eclipse.refreshLocal resource="hibernate.music/src" depth="infinite"/>
</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">
<classpath refid="project.class.path"/>
</javac>
</target>

<!-- Generate the schemas for all mapping files in our class tree -->
<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="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>

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

<target name="ctest" description="Creates and persists some sample data"
depends="compile">
<java classname="com.oreilly.hh.CreateTest" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>

<target name="qtest" description="Run a simple Hibernate query"
depends="compile">
<java classname="com.oreilly.hh.QueryTest" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>

</project>

eclipse console running ant codegen:

Buildfile: C:\eclipse-3.1M5a.0\workspace\hibernate.music\build.xml

prepare:

codegen:
[hbm2java] Processing 2 files.
[hbm2java] Building hibernate objects
[hbm2java] org.hibernate.MappingException: An association from the table TRACK_ARTISTS refers to an unmapped class: com.oreilly.hh.Track
[hbm2java] at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:944)
[hbm2java] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:897)
[hbm2java] at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:825)
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.parseFiles(CodeGenerator.java:115)
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:95)
[hbm2java] at org.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at org.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:341)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[hbm2java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[hbm2java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:674)
[hbm2java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:433)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
[hbm2java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
[hbm2java] at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
[hbm2java] at org.eclipse.ant.core.AntRunner.run(AntRunner.java:355)
[hbm2java] at org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:210)
[hbm2java] at java.lang.Thread.run(Thread.java:568)
[hbm2java] org.hibernate.MappingException: An association from the table TRACK_ARTISTS refers to an unmapped class: com.oreilly.hh.Artist
[hbm2java] at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:944)
[hbm2java] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:897)
[hbm2java] at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:825)
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.parseFiles(CodeGenerator.java:115)
[hbm2java] at org.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:95)
[hbm2java] at org.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at org.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:341)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[hbm2java] at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
[hbm2java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:674)
[hbm2java] at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:433)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
[hbm2java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
[hbm2java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
[hbm2java] at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
[hbm2java] at org.eclipse.ant.core.AntRunner.run(AntRunner.java:355)
[hbm2java] at org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:210)
[hbm2java] at java.lang.Thread.run(Thread.java:568)
BUILD SUCCESSFUL
Total time: 7 seconds

problem:

I'm trying to generate Java code using the Track and Artist mapping files using the above ant script under eclipse 3.1.0, and I get the MappingExceptions displayed on the console. What's wrong?

Thanks.

Lou.


Top
 Profile  
 
 Post subject: Further Frustration
PostPosted: Wed Apr 06, 2005 10:01 am 
Newbie

Joined: Tue Apr 05, 2005 10:08 am
Posts: 2
Just to add to your frustration, another post claiming the same problem but with no solution.

I am also seeing this issue but can find no resolution as yet.

Alan

_________________
-------------
Alan Parry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2005 10:18 am 
Newbie

Joined: Tue Apr 05, 2005 10:08 am
Posts: 2
Some further information.

I am able to make this compile be regressing to hibernate 2.1 under eclipse. I am using Tomcat as an application server and am unable to get this to work with hibernate 2.1. I see lots of other problems unless I upgrade to hibernate 3.0 as the online tutorial shows on this site. If i do this however i see the same problem with my classes and mapping documents generated with hibernate 2.1 so no progress.

Is the syntax for many-to-many relationships the same in hibernate 3.0 as in hibernate 2.1. If i remove the relationships then my classes stop complaining.

Thanks,
Alan

_________________
-------------
Alan Parry


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 11, 2005 2:48 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:26 am
Posts: 22
did you try and define the mappings (Artist , etc...) in hibernate.cfg.xml ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 10:55 am 
Newbie

Joined: Thu Apr 21, 2005 10:45 am
Posts: 2
Location: London, UK
I've tried it with the mappings in the config and without them, same result. I can't see this raised as a bug in Jira - so I'm guessing someone's figured out a solution...?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 8:40 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:26 am
Posts: 22
post your hibernate.cfg.xml


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 9:35 am 
Newbie

Joined: Thu Apr 21, 2005 10:45 am
Posts: 2
Location: London, UK
As below - as I said, I tried removing the mappings with no effect. I've since tried doing the same codegen using the hibernate2 jar and it worked ok. To be fair, I guess the toolkit is only alpha...

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
    <property name="hibernate.connection.url">jdbc:hsqldb:data/music</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password"/>
    <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
    <property name="show_sql">true</property>
    <property name="transaction.factory_class">
             org.hibernate.transaction.JDBCTransactionFactory
        </property>
    <property name="hibernate.cache.provider_class">
             org.hibernate.cache.HashtableCacheProvider
        </property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <mapping resource="com/ovid/hdn/Track.hbm.xml"/>
    <mapping resource="com/ovid/hdn/Artist.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Workaround
PostPosted: Thu May 05, 2005 6:24 pm 
Newbie

Joined: Thu May 05, 2005 6:08 pm
Posts: 1
I ran into this too... same book I guess ;-)

Anyway, for grins, I tried cut/paste the contents of artist.hbm.xml into track.hbm.xml, and then deleted artist.hbm.xml. Seems better now.

_________________
.rob.park.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 13, 2006 7:32 pm 
Newbie

Joined: Sun May 07, 2006 4:40 am
Posts: 1
Hey Guys,

You need to add .configure() to your configuration class to pick up your hibernate.cfg.xml or pass the name like in .configure("xxx.cfg.xml").

If you are not using .cfg.xml and like to pass the .hbm.xml (with .addFile method) or repective persistent class in your application (test class in this case), ensure you have the below...

.addClass(Track.class).addClass(Artist.class);

The book has the latter example in place...

Refer "Chapter 3. SessionFactory Configuration" from the reference document

Hope this helps.

Or if your issue is not solved, post your test code in here...

Mahesh Devendran


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