-->
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: Example Uni-Directional Many-to-Many Association???
PostPosted: Thu May 10, 2007 5:37 pm 
Beginner
Beginner

Joined: Tue Apr 24, 2007 2:03 pm
Posts: 23
I would greatly appreciate it if someone could point me to an example of a uni-directional many-to-many association (uses link table) that is confirmed (read tested) to work with hibernate 3.1.

I have been unable to come up with an example where my link table is updated. The two tables I am joining get updated just not the link table.

I have a few books that give examples (Pro Hibernate 3) but I cannot even get them to work.

I am using Hibernate 3.1, MySQL, and JBOSS 4.0.4. My IDE is MyEclipseIDE 5.1.1GA.

Thanks,
Pneu


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 9:44 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
try something like this:

mapping for class Publisher:

<set name="authors" table="PUBLISHER_AUTHOR" cascade="all">
<key column = "PUBLISHER_ID" />
<many-to-many column="AUTHOR_ID"
unique="true"
class="Author"/>
</set>

there is no corresponding entry in the mapping for class Author, as is is unidirectional.

For the future, note if you want to get help here you are expected to give all your relevant mappings and code in your postings.
Good luck


Top
 Profile  
 
 Post subject: Current Mapping Files Provided
PostPosted: Fri May 11, 2007 11:16 am 
Beginner
Beginner

Joined: Tue Apr 24, 2007 2:03 pm
Posts: 23
Thanks for reply. Here are my mapping files. I've supplied them before but never got any responses so I'm posting them again based on the feedback in the previous message. Given this mapping, no rows get inserted into my link_customer_address table when I insert a Customer that has an Address. The customer and address tables are populated with a single row each.

Here is the mapping for my customer table (customer.hbm.xml)

FYI...the link_customer_address table defines two columns,
customer_id
address_id

the primary key is a composite of the two columns and I've defined two FK relationships back to each of the respective related tables (customer, address).

<hibernate-mapping>
<class name="com.receptrix.hibernate.Customer" table="customer" catalog="reservation">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="native" />
</id>
<property name="lastName" type="java.lang.String">
<column name="last_name" length="50" not-null="true" />
</property>
<property name="firstName" type="java.lang.String">
<column name="first_name" length="50" not-null="true" />
</property>
<property name="middleInitial" type="java.lang.String">
<column name="middle_initial" length="1" />
</property>
<property name="suffix" type="java.lang.String">
<column name="suffix" length="5" />
</property>
<property name="phone" type="java.lang.String">
<column name="phone" length="13" />
</property>
<property name="phoneType" type="java.lang.String">
<column name="phone_type" length="10" />
</property>
<property name="emailAddress" type="java.lang.String">
<column name="email_address" length="100"/>
</property>
<set name="addresses" table="link_customer_address" cascade="save-update">
<key column="customer_id"/>
<many-to-many class="com.receptrix.hibernate.Address" column="address_id"/>
</set>
</class>
</hibernate-mapping>

****** address table mapping **********
<hibernate-mapping>
<class name="com.receptrix.hibernate.Address" table="address" catalog="reservation">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="native" />
</id>
<property name="addressLine1" type="java.lang.String">
<column name="address_line_1" length="100" not-null="true" />
</property>
<property name="addressLine2" type="java.lang.String">
<column name="address_line_2" length="100" />
</property>
<property name="city" type="java.lang.String">
<column name="city" length="50" not-null="true" />
</property>
<property name="stateProvince" type="java.lang.String">
<column name="state_province" length="50" not-null="true" />
</property>
<property name="countryCode" type="java.lang.String">
<column name="country_code" length="2" not-null="true" />
</property>
<property name="zipCode" type="java.lang.String">
<column name="zip_code" length="5" not-null="true" />
</property>
<property name="zipExtension" type="java.lang.String">
<column name="zip_extension" length="4" />
</property>
</class>
</hibernate-mapping>

Regards,
J.D.


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.