-->
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.  [ 4 posts ] 
Author Message
 Post subject: collection of subclasses - stumped
PostPosted: Tue Oct 21, 2003 7:12 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 6:24 pm
Posts: 45
Hi All -
I'm stumped on how to map a collection of subclasses in such a way that each collection of subclasses is initialized with only "subclass" type of entities.

background:
Our db schema, however bad, is such that:
- we have Parent and Child entities
- child entities are one of 3 "types", (think type=discriminator; 3 subclasses)
- Parent has 3 collections - one for each "type" of child
- Parent-Child mapping is stored in a single mapping table with 2 columns (parent id and child id)

2 possible approaches:

1. use discriminator - this is a problem, since collections do not pay attention to discriminator value when loaded (according to http://forum.hibernate.org/viewtopic.ph ... n+subclass). Result is that if Parent has 10 children of type x, 5 children of type y, 6 children of type z - the Parent collections end up with 21 objects each.

2. use where clause in collection mapping - this is a problem, since the discrimintor column is not available in the mapping table. I'm not sure if the sql generated in this case is correct, but it will not work in this case - the "where" attribute is assumed (by hibernate) to be applied to the table referenced in the collection mapping (i.e. my parent-child mapping table), instead of the child table.

example mapping:
<bag
name="offers"
table="eye_offer_category"
lazy="true"
inverse="false"
cascade="none"
order-by="offer_sys_id"
where="offer_type=0"
>
<jcs-cache
usage="read-write"
/>

<key
column="target_category_sys_id"
/>

<many-to-many
class="com.eyetide.model.Offer"
column="offer_sys_id"
outer-join="auto"
/>

</bag>

Offer mapping is something like:
<class
name="com.eyetide.model.Emu"
table="eye_offer"
dynamic-update="false"
dynamic-insert="false"
>
<property
name="offerType"
type="com.eyetide.constants.OfferType"
update="true"
insert="true"
column="offer_type"
/>

this generates sql like:
...from eye_offer_category alias1, eye_offer alias2 where alias1.offer_type=0...

which is bogus (should be "alias2.offer_type=0")


any thoughts?

thanks
tyson


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use the where attibute of the collection mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 8:54 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 6:24 pm
Posts: 45
gavin wrote:
Use the where attibute of the collection mapping.


...er this is a problem since the discriminating column is NOT available in the mapping table, only in the child entity table.

The "where attribute" of the collection mappping appears to generate SQL referencing the *mapping table*, not the child table.

In my case, tables are like:

table_parent:
int id
String name

table_child:
int id
String name
int type

table_parent_child
int parent_id
int child_id

So....when I specify a where attribute for the collection, the sql generated is:

....where table_parent_child.type=x and...

which definitely fails. I need, instead:

....where table_child.type=x and...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 9:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh its a many-to-many. Yeah, this is not supported.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.