-->
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.  [ 13 posts ] 
Author Message
 Post subject: Ternary mapping help
PostPosted: Wed Sep 03, 2003 10:15 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
[I accidentally posted this as a reply to a previous topic. Sorry]

Can someone please provide an example ternary mapping of tables A, B and C though the join table ABC.

I'm looking for something like this,

Code:
A--ABC--B
    |
    C


Any suggestions?

Thanks,
-Mitch

P.S. I have seen the example in the Reference Document and searched the forum, but still can't figureout the syntax.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 10:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You have two choices:

* use a Map with an <index-many-to-many>
* use a <composite-element>

which do you want?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 10:46 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I'm not sure of the difference (sorry).

Can you give an example of the Map with <index-many-to-many>?

I'm not sure how difficult that is, I haven't had any luck yet. :)

Thanks for responding.

-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 11:12 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
Maybe a better question is whether there is a better tutorial on mapping than the Hibernate2 Reference Documentation. I've gone through that a couple of times now, front to back and still don't grasp anything but the simplest of mappings.

Any suggestions?

-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 8:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
By way of an example, here is my ternary association betwen groups and the various entitlements that group has to system use cases.
Code:
<class name="SecurityGroup" table="v_group">
    ...
    <map
            name="useCaseEntitlementMap"
            table="use_case_entitlement"
            lazy="false"
            inverse="false"
        >
            <key column="group_id"/>
            <index column="use_case_name" type="UseCaseType"/>
            <element column="use_case_entmt" type="EntitlementType"/>
        </map>
</class>


So on my SecurityGroup class, I can lookup the groups entitlement to a given use case by doing
Code:
securityGroup.getUseCaseEntitlementMap().get( UseCase.CREATE_USER );


In my system, use cases and entitlements are enums, hence the special types in the map mapping. If you want simple types, say strings, the mapping is even easier:
Code:
<class name="SecurityGroup" table="v_group">
    ...
    <map
            name="useCaseEntitlementMap"
            table="use_case_entitlement"
            lazy="false"
            inverse="false"
        >
            <key column="group_id"/>
            <index column="use_case_name" type="string"/>
            <element column="use_case_entmt" type="string"/>
        </map>
</class>


HTH


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 9:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Further, say for your association diagram you have classes: ClassA, ClassB, and ClassC. Assume that ClassA and ClassB are already mapped. Then in ClassC you want to map the association represented by ABC:

Code:
<class name="ClassC" table="C">
    ...
    <map
            name="alphaToBetaMap"
            table="ABC"
            ...
        >
            <key column="c_id"/>
            <index-many-to-many column="a_id" type="ClassA"/>
            <many-to-many column="b_id" type="ClassB"/>
        </map>
</class>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 1:07 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
Is the assumption then that similar mappings exist for tables 'A' and 'B'?

Specifically,
Code:
<class name="ClassA" table="A">
    ...
    <map
        name="betaToGammaMap"
        table="ABC"
        ...
        >
            <key column="a_id"/>
            <index-many-to-many column="b_id" type="ClassB"/>
            <many-to-many column="c_id" type="ClassC"/>
    </map>
</class>

<class name="ClassB" table="B">
    ...
    <map
        name="alphaToGammaMap"
        table="ABC"
        ...
        >
            <key column="b_id"/>
            <index-many-to-many column="a_id" type="ClassA"/>
            <many-to-many column="c_id" type="ClassC"/>
    </map>
</class>


I apologize if this is a naive question.

I'm going to test it as soon as I get a chance, but if someone knows off the top of their head, that would be nice.

Thanks,
-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Is the assumption then that similar mappings exist for tables 'A' and 'B'?


Depends what you mean by "similiar". Certainly ClassA and ClassB must be mapped. They dont necessarily have to have understanding of the ternary association in which the participate with ClassC if you don't want them to.


Top
 Profile  
 
 Post subject: How do you map the same scenario with composite-element?
PostPosted: Tue Oct 21, 2003 1:15 pm 
Newbie

Joined: Tue Oct 21, 2003 1:09 pm
Posts: 4
Hi-,
I'm a newbie trying to grasp the concepts of ternary association in hibernate. I want to know how do you map the same scenario with composite element. i went throught he examples in doc. but still i'm not grasping the concept as i'm new to the persistence(DB) side also.If you can expalin it that will be helpful.

Thanks

Hans


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 11:34 am 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I'm sorry, but I haven't attempted ternary associates via composite elements. After spending a couple of days finding out that cascading saves don't apply to the key of a ternary mapping, I simply got things working the best I could and moved on.

I was able to get my ternary relationship mapped sufficiently (though not optimally IMHO).

...which leads me to the following tangent:

Hibernate leaves *much* to be desired in terms of documentation. Hopefull at some point Gavin et al. will realize that whatever magic he/they develop may be useless without sufficient documentation.

My experience has been that if you live/eat/breathe Hibernate, it is a very effective tool. But for a casual user, who also needs to tend to architecture, GUI, build processes, etc. and want's to use Hibernate to simplify/eliminate data mapping from their already full plate, Hibernate is a bit of a time sink.

I attribute this solely to poor documentation rather than poor design or lack of features.

As long as everything is working fine, I love Hibernate. But as soon as I get that inevitable email that some of the data isn't mapping properly, I get that sinking feeling that I'm about to invest another significant amount of time trying to 'guess' what Hibernate wants me to do next.

...sorry for sidestepping your original question. :)

-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 2:18 pm 
Newbie

Joined: Fri Dec 05, 2003 2:12 pm
Posts: 2
Location: Montpellier France
I'm trying to update the 3 columns of a ternary association and it does not work for the index and element columns, your right! You wrote : "I simply got things working the best I could and moved on. "
May I ask how you "got things working the best"?
Thanks
Ced


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 2:43 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I originally wanted my primary object to have a Map, the key of which related to one table, and the value to another. As I said earlier, cascading saves *only* work for the 'value' not the 'key'.

Pictorially, my 'optimal' solution looks like this,
Code:
    C
   /
A-+
   \
    D


Unfortunately, saving A cascades the save to D but not C (the Map key).

My solutions was to the move the ternary mapping to a fourth object.

Since I can't relate A directly to C and D with a Map in A, I had to create a new B object who's sole purpose is to relate A, C and D. Then I added a java.util.List of B objects to my A object.

Pictorially, my solution looks like this.
Code:
     C
    /
A->B
    \
     D


My B has a primary key and a reference to an A, B and C object.

With this approach, I am able to cascade saves throughout.

-Mitch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:51 am 
Newbie

Joined: Wed Dec 24, 2003 11:33 pm
Posts: 3
create table abc(
a_id VARCHAR2(32) not null,
b_id VARCHAR2(32) not null,
c_id VARCHAR2(32) not null,
primary key (a_id, b_id)//(a_id,b_id,c_id)
);


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