-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping file help, please
PostPosted: Fri Aug 20, 2004 1:44 pm 
Newbie

Joined: Fri Aug 13, 2004 12:06 pm
Posts: 15
Hibernate version:2.1

Mapping documents:included

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:

Can some expert PLEASE help? This simple requirement appears as though it is impossible to do with Hibernate:

Image

I want Bands class to hold a collection of Recordings, but I also want Recordings to be independent of Bands; i.e. I want to be able to query for recordings by bandname and song title.

After trying unsuccessfully for many days by creating the mapping files manually, and then using hbm2java and the schema generator to generate the source files and database schema, I decided to try creating the SQL script to create the tables and then let Middlegen create the mapping file, from which I could create the JavaBeans and the schema again.

Problems:
1) Middlegen worked fine and created three mapping files, but when I tried to use the ant task to recreate the schema from the mapping files, it stopped with an error (the composite id was not correct). In other words, I can't recreate the schema from the mapping files created by the tool that generated them from a working schema!

2) I can't retrieve recording beans without knowing a bandbean; i.e. they are not independent.

3) I can't ask for a Recording by bandname and title. (See the Recording's composite ID... it uses a Band bean and title).

Any help would be a huge help. This is what Middlegen-Hibernate-r3 created:

BANDS:

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

<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="bands.hibernate.Band"
table="BANDS"
>

<id
name="name"
type="java.lang.String"
column="NAME"
>
<generator class="assigned" />
</id>

<property
name="startdate"
type="java.sql.Date"
column="STARTDATE"
/>
<property
name="founder"
type="java.lang.String"
column="FOUNDER"
length="150"
/>
<property
name="wlsTemp"
type="int"
column="WLS_TEMP"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to Recording -->
<set
name="recordings"
lazy="true"
inverse="true"
>
<key>
<column name="BANDNAME" />
</key>
<one-to-many
class="bands.hibernate.Recording"
/>
</set>

</class>
</hibernate-mapping>


RECORDING:

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

<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="bands.hibernate.Recording"
table="RECORDING"
>

<composite-id name="comp_id" class="bands.hibernate.RecordingPK">
<key-property
name="title"
column="TITLE"
type="java.lang.String"
length="150"
/>
<!-- bi-directional many-to-one association to Band -->
<key-many-to-one
name="band"
class="bands.hibernate.Band"
>
<column name="BANDNAME" />
</key-many-to-one>
</composite-id>

<property
name="rating"
type="java.lang.String"
column="RATING"
length="150"
/>
<property
name="bandejbName"
type="java.lang.String"
column="BANDEJB_NAME"
length="150"
/>
<property
name="wlsTemp"
type="int"
column="WLS_TEMP"
/>

<!-- associations -->

</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.