-->
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: Issue with many-to-many mapping
PostPosted: Thu Jun 19, 2014 10:41 am 
Newbie

Joined: Thu Jun 19, 2014 10:12 am
Posts: 1
For some reason my many-to-many mapping is not working from both sides. Here is the outline of my setup -

I have the following database tables -
1. accounts with acc_id as primary key
2. custom_field_list with cf_id as primary key
3. custom_field_mapping with cf_id_map and acc_id_map as primary key

Java classes:-

1. Account with a getCustomFields() method
2. CustomField with a getAccounts() method

Here are the Hibernate mappings for the 2 classes -

<hibernate-mapping>
<class
name="Account"
table="accounts">

<id name="id" column="acc_id">
<generator class="native"/>
</id>

<set name="customFields" table="CUSTOM_FIELD_MAPPING" cascade="all">
<key column="acc_id_map" />
<many-to-many column="cf_id_map" class="CustomField" />
</set>
</class>
</hibernate-mapping>



<hibernate-mapping>
<class
name="CustomField"
table="CUSTOM_FIELD_LIST">

<id name="id" column="CF_ID">
<generator class="native"/>
</id>


<set name="accounts" table="CUSTOM_FIELD_MAPPING" cascade="all">
<key column="cf_id_map" />
<many-to-many column="acc_id_map" class="Account"/>
</set>


</class>
</hibernate-mapping>

Data is getting setup correctly in the db.

The issue that I am facing that when I access the customFields from Account instance by using the the following code -
List accs = session.createQuery("FROM Account").list();

things work i.e the getCustomFields() method on the Account class returns the list of custom field objects.

However when I access the accounts from the CustomField instance by using the following code -

List customFields = session.createQuery("FROM CustomField").list();

things do not work i.e the getAccounts() method on the CustomField class does not return the list of account objects.

In other words, the many-to-many mapping is working from one side.
Let me know if I have setup anything incorrectly.


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.