-->
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: question for many-to-many mapping
PostPosted: Tue Jun 06, 2006 9:38 am 
Newbie

Joined: Wed Apr 12, 2006 10:29 am
Posts: 3
Hi, folks

I am learning Hibernate and I am following the book 'hibernate quickly'. When I run the the example from the website site(http://www.manning.com/peak/, following the source code link) for chapter 5, after running the ant to create the tables, I found that in the 'join' or 'link' tables between the 2 tables, m_events & m_attendees, and the 'link' table, event_attendees, which should have only 2 PKs from the 2 tables, has an unexpected column, named 'elt'?

The mapping files are the follows:

//======= EventManyToMany.hbm.xml =======//

<?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>
<class name="com.manning.hq.ch05.manytomany.EventManyToMany" table="m_events">
<id name="id" column="uid" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string" length="100"/>
<property name="startDate" column="start_date"
type="date"/>
<property name="duration" type="integer"/>
<many-to-one name="location" column="location_id"
class="com.manning.hq.ch05.manytomany.LocationManyToMany"/>
<set name="speakers" table="event_speakers" cascade="all">
<key column="event_id"/>
<many-to-many class="com.manning.hq.ch05.manytomany.SpeakerManyToMany"/>
</set>
<set name="attendees" table="event_attendees" cascade="all">
<key column="event_id"/>
<many-to-many class="com.manning.hq.ch05.manytomany.AttendeeManyToMany"/>
</set>

</class>
</hibernate-mapping>

//=== AttendeeManyToMany.hbm.xml =====//

<?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>
<class name="com.manning.hq.ch05.manytomany.AttendeeManyToMany" table="m_attendees">
<id name="id" column="uid" type="long">
<generator class="native"/>
</id>
<property name="firstName" type="string" length="20"/>
<property name="lastName" type="string" length="20"/>
<set name="events" table="event_attendees" cascade="all">
<key column="attendee_id"/>
<many-to-many class="com.manning.hq.ch05.manytomany.EventManyToMany"/>
</set>

</class>
</hibernate-mapping>

The resultant 'event_attendees' table will have structure like this:

event_id elt attendee_id

The 'elt' field is the one that is confusing me.

Could anyone give me some hints why hibernate created such field?

Btw, I have hibernate 3.0.

Thanks in advance!

X.Chen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 9:55 am 
Newbie

Joined: Wed Apr 12, 2006 10:29 am
Posts: 3
Just got it. That change I made is like this :

//======= EventManyToMany.hbm.xml =======//
...

set name="attendees" table="event_attendees" cascade="all">
<key column="event_id"/>
<many-to-many column="attendee_id" class="com.manning.hq.ch05.manytomany.AttendeeManyToMany"/>
</set>


//=== AttendeeManyToMany.hbm.xml =====//
...

<set name="events" table="event_attendees" cascade="all">
<key column="attendee_id"/>
<many-to-many column="event_id" class="com.manning.hq.ch05.manytomany.EventManyToMany"/>
</set>

Notice the symetry by adding the 'column' attribute in both file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 3:55 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
FYI, the "elt" symbol that has been mentioned in several posts is the default column name hibernate uses. It generally indicates that you failed to provide some mapping information for a key column, so Hibernate makes one up.


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.