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: problem mapping m:n lists
PostPosted: Wed Oct 20, 2004 6:29 pm 
Newbie

Joined: Wed Oct 20, 2004 5:35 pm
Posts: 1
I have two entities, report and rule. Each report is connected to zero or more rules and each rule is connected to zero or more reports.

I choose to map the entities as lists, because the order of the rules connected to each report is important.

In my Report.hbm.xml, I mapped

<!-- Each report is connected to zero or more rules -->
<!-- we have a n:m relationship here -->
<!-- ordering is important -->
<list name="rules" table="APP_REPORT_RULE" lazy="true" cascade="none">
<key column="ID_REPORT"/>
<index column="SORTING"/>
<many-to-many column="ID_RULE" class="itoskop.bo.Rule"/>
</list>


And in my Rule.hbm.xml I mapped:

<!-- m:n relationship reports -->
<list name="reports" table="APP_REPORT_RULE" lazy="true" cascade="none" inverse="true">
<key column="ID_RULE"/>
<index column="SORTING"/>
<many-to-many column="ID_REPORT" class="itoskop.bo.Report"/>
</list>



When I run hbm2ddl, I get (partly) this SQL:

create table APP_REPORT_RULE (
ID_REPORT INTEGER not null,
ID_RULE INTEGER not null,
SORTING INTEGER not null,
primary key (ID_RULE, SORTING)
);



which is not exactly what I expected, because this prevents me from associating one rule to more than one report on the same index position.
If I had modelled the schema by hand, the primary key would have been more like:

...
primary key (ID_RULE, SORTING)
...



What is wrong with my mapping (since it is not really m:n)? Or can't I do that with lists?

Andy


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.