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