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: strange problem with file .hbm.xml
PostPosted: Thu Mar 02, 2006 11:05 pm 
Newbie

Joined: Mon Feb 13, 2006 12:30 pm
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.2
Eclipse version: 3.1

Mapping documents:
Track.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 3, 2006 12:30:55 AM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping package="chapter2">
<class name="Track" table="TRACK">
<id name="id" type="integer">
<column name="Track_ID" />
<generator class="native"></generator>
</id>
<property name="title" type="string">
<column name="TITLE" not-null="true" index="TRACK_TITLE"/>
</property>
<property name="filePath" type="string">
<column name="filePath" not-null="true" />
</property>
<property name="playTime" type="time">
<column name="playTime" />
</property>
<set name="artists" table="TRACK_ARTISTS">
<key column="TRACK_ID" />
<many-to-many class="Artist"
column="ARTIST_ID" />
</set>

<property name="added" type="date">
<column name="added" />
</property>
<property name="volume" type="short">
<column name="volume" />
</property>
</class>
</hibernate-mapping>

Artist.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 3, 2006 12:30:54 AM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping package="chapter2">
<class name="Artist" table="ARTIST">
<id name="id" type="integer">
<column name="ARTIST_ID" />
<generator class="native"></generator>
</id>
<property name="name" type="string">
<column name="NAME" not-null="true" unique="true" />
</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="Track" column="TRACK_ID" />
</set>

<query name="chapter2.artistByName">
<![CDATA[
from Artist as artist
where upper(artist.name) = upper(:name)
]]>
</query>
</class>
</hibernate-mapping>


Name and version of the database you are using: hsqldb 1.8

hsqldb-hibernate.cfg.xml
<?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>

<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:file:build/data/canhac;hsqldb.default_table_type=cached;shutdown=true</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->


<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>


<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="chapter2/Track.hbm.xml"/>
<mapping resource="chapter2/Artist.hbm.xml"/>
</session-factory>

</hibernate-configuration>

********************************
code to build session factory :

File f = new File("F:/ZZZ/hsqldb-hibernate.cfg.xml");
Configuration config = new Configuration();
config.configure(f);

//Tell it about classes we want mapped if we did not
//declare in the .cfg.xml file
config.addClass(Artist.class);

//Get the session factory we can use for persistence
SessionFactory sessionFactory = config.buildSessionFactory();


The problem is: without the line config.addClass(Artist.class), i get the mapping exception (an association table refer ...unknown mapping class ...) . Why ? I declared mapping Artist in file hsqldb-hibernate.cfg.xml . Why i need to declare here once more ? But here, if i declare for Track class , like config.addClass(Track.class) , i get a duplicate mapping exception ( certainly, i understand) . But how about Artist , what wrong here ? Please help me .Thank you !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 11:14 pm 
Newbie

Joined: Mon Feb 13, 2006 12:30 pm
Posts: 12
once more question :
the query above , if i put it in Artist.hbm.xml , i got unknown query name error , but if i put it in Track.hbm.xml , it is ok !!! i think for both problem, hibernate does not see Artist.hbm.xml. why ? it is in the same directory as Track.hbm.xml .
Please help me.
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 2:52 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
it really sounds like a classpath problem and/or a directory - do a find (or search) for the Artist and Track in your dirs and see if you can come up with extras..or not where they're supposed to be...etc. Also you may want to standardize on one way to load the mappings...

See this posting of mine that discusses using hibernate.cfg.xml vs hibernate.properties - Personally I use the .properties way and then do the addClass for each class I want to configure into my sessionfactory...


Here is the other post for when .properties vs. cfg.xml files are read.

[url]http://forum.hibernate.org/viewtopic.php?t=956099&highlight=hibernate+properties
[/url]

Let me know if that helps...

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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.