-->
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.  [ 10 posts ] 
Author Message
 Post subject: Variable one-to-many - use of <any>?
PostPosted: Tue Mar 02, 2004 10:41 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Hi everyone,

I'm trying to map the following relations:

Code:

A
  \
B - INDEX - E
  /
C

INDEX
---------------------
TYPE
ID
IdE




That you can translate by:
A has a subset of E
B has a subset of E
C has a subset of E

the index allows to map an entity E with any entity A, B or C identified by ID (A, B & C have the same kind of Identifier) and thanks to the TYPE column (A, B or C)

I believe I should use the something like that for the INDEX

Code:
<class name="INDEX">
   <any name="INDEX" id-type="String" meta-type="class">
      <column name="IdE"/>
      <column name="ID"/>
   </any>
</class>


but I've read
Quote:
...and should also be used rarely, if ever.
in the doc, so I wonder if it's really safe to use it?

Now I don't need a collection of <any> type, I need 3 collections of E entity, one for A, for B, for C... I'm wondering how to implement a <map> of E entity for each of these object.


I watched carrefully the forum but exmaples on this are rather slim (or difficult to find out)
Thanks in advance for any hints.


Last edited by nodje on Tue Jun 03, 2008 5:37 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 11:24 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Actually I think I took the problem the other way around.

I always know what kind of entity collection I desire for my A B C entities.

So the question would rather be how could the <key> element of the <map> reference a TYPE and an ID

Code:
<map name="engagement" table="INDEX">
            <key column="ID"/>
            <index-many-to-many class="E" column="IDE"/>
</map>


What could I possibly add to the mapping for it reference only entities with of a certain TYPE?

I could use a <composite -id> but then I would have to map INDEX table.
A simple <many-to-many> should be sufficient to ref the composite key though.

Any advice or thoughs about that?
thanks in advance for any help!


Last edited by nodje on Tue Jun 03, 2008 5:37 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 12:58 pm 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Could someone tell me if discriminator-value could be of any help for my problem or if it is only for subclassing purpose as it looks like?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 5:03 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
Sorry guys, I must be really dumb but I can't figure out a solution for my variable one-to-many problem.

I'm stuck and fear to have to implement 3 index tables, one for each A B C, entity which is the only solution available for me now

Any hints would be greatly appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
nodje wrote:
Could someone tell me if discriminator-value could be of any help for my problem or if it is only for subclassing purpose as it looks like?

No it won't help

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:30 pm 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
I'm screening the documentation from beginning to end since i'm really stucked.

So I figured out I cound't get anything from that discriminator stuff!

But thanks anyway for answering!
Coz up to now I'm making questions and answers!!

But still, I don't see any solution coming up.

If I use a <any> I could have an INDEX object containing pairs like (A, E) (B, E) or (C, E) which is not what I want indeed.

I really need a SortedSet of E for each object A, B & C and I end up thinking there's no way to automatize that.
So or I develop some code to build my SortedSet or I create 3 index, INDEX_AE, INDEXBE, INDEX_CE which not nice at all from a PDM point of view but quite simpler from hibernate's one!

Any confirmation of my guesses is still welcome...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 3:18 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
give complete table description with pk and fk


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can do something implementing the Lifecycle interface to manually map your needs.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:17 am 
Regular
Regular

Joined: Fri Nov 07, 2003 6:31 am
Posts: 104
Location: Beijing, China
I can sum it up very shortly

Code:
TABLE A
----------------------
ID_A
FIELD_A

TABLE B
-----------------------
ID_B
FIELD_B

TABLE C
-----------------------
ID_C
FIELD_C

TABLE E
-----------------------
ID_E
FIELD_E

INDEX
-----------------------
ID_E (PK)
TYPE
ID



Each records in E belongs to A OR B OR C
A, B & C have the same ID strcture so that I can reference ID_A, ID_B_ or ID_C with TYPE (being A or B or C) and ID. I can't settle any FK here though, because it's variable.

To put it simply INDEX allows me to select a subset of E for each A, B and C.

Moreover, it'a unidirectional, I never need to know to what table (A, B or C) a record E is related.


Lifecycle object is definitely an option to consider. Not simple though, I'd have to implement some queries in it which doesn't sound very proper to me.
ON top of that I'm wondering if performance wise CallBacks are OK?
I already use them to replace any attribute with an empty String ("") with a null, that means object is screened before any SAve or Update and I must say I'm a bit afraid of that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 4:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You know, refactoring you DB should be the best option if available

_________________
Emmanuel


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