-->
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: Many-To-Many via two columned Unique-Key
PostPosted: Thu Jun 08, 2006 10:01 am 
Newbie

Joined: Thu May 18, 2006 4:31 am
Posts: 12
Location: Germany
Hibernate version:
3.1.3

Anything else: Inside the text

Hello,

I have a problem that I just cannot cope. It is about the in the forum already discussed topic of an many-to-many relationship with extra attributes in the association table.

The table structure is unchangeable and is as follows:

Code:
CREATE TABLE `message` (
  `id` int(11) NOT NULL,
  `customer_nr` varchar(20) default NULL,
  `content` varchar(50) default NULL,
  PRIMARY KEY  (`id`)
);


CREATE TABLE `message_recipient` (
  `id` int(11) NOT NULL,
  `message_id` int(11) default NULL,
  `rec_user_name` varchar(20) default NULL,
  `rec_customer_nr` varchar(20) default NULL,
  `received` bit(1) default NULL,
  `received_date` date default NULL,
  PRIMARY KEY  (`id`)
);


CREATE TABLE `recipient` (
  `id` int(11) NOT NULL,
  `customer_Nr` varchar(20) default NULL,
  `user_name` varchar(20) default NULL,
  `gebDatum` date default NULL,
  PRIMARY KEY  (`id`)
);

The association table has extra columns (Received, Received_Date).
The RECIPIENT table has an unique key on (USER_NAME, CUSTOMER_NR).
The reference in the association table to the Recipient is via the two unique properties of Recipient (REC_USER_NAME, REC_CUSTOMER_NR).

I created an association class "MessageForRecipient" which holds the additional attributes.

Navigability: I don't know if in this case a bidirectionality is possible. I would like to navigate from a recipient to all of his messages via MessageForRecipient, and vice versa.

I read about similar models in this forum, so I tried to use a composite-element for the association class.
This is how I tried to model the association from a Message to all of its recipients:

Code:
<hibernate-mapping>
    <class name="Message">
...
    <set name="recipients" table="message_recipient">
      <key column="message_id" />
      <composite-element class="MessageForRecipient">
        <many-to-one name="recipients" class="Recipient"
          property-ref="uk_recipient">
          <column name="rec_user_name" />
          <column name="rec_customer_nr" />
        </many-to-one>
        <property name="receivedDate" column="received_date" />
      </composite-element>
    </set>


This is the unique property of Recipient:

Code:
<hibernate-mapping>
    <class name="Recipient">
    ...
    <properties name="uk_recipient">
       <property name="userName" column="user_name"></property>
       <property name="customerNr" column="customer_nr"></property>
    </properties>




The result is that I get a ConcurrentModificationException (just as mentioned in http://opensource.atlassian.com/project ... se/HHH-971).

Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1013)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)
... 3 more

There should be another way to solve my problem that I don't know. Any help is greatly appreciated.

Jan


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.