-->
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: How to use ternary associations codewise?
PostPosted: Fri Jan 09, 2004 8:04 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi all!
First: thanks for a great product!

Second: Hav e been reading the topics concerning the ternary association, and I also managed to get a mapping via XDoclet after a couple of hours trial-and-error.

The problem is that I don't really get the idea by ternary associations usage-wise. I mean, what kind of code etc. should you use on an association like the one below? I'm feeling a bit confused, I have managed to map it, but I don't know how to use it. If u see what I mean.

I have the following situation:

An InfoContact object holds a Map with data for the contact. The Map is indexed by a ContactField object which contains fieldname, a bit of HTML-info etc. This field object holds a Set of ContactMeta objects, containing option values, encoding and such.

ContactField----CF_IC_CM----ContactMeta
|
|
InfoContact

Mapping in InfoContact:

<map
name="data"
table="CONTACT_DATA"
lazy="true"
sort="unsorted"
inverse="false"
cascade="none"
>

<key
column="CONTACT_FK"/>

<index-many-to-many
class="ks.rah.cainfo.db.model.ContactField"/>

<many-to-many
class="ks.rah.cainfo.db.model.ContactMeta"
column="VALUE_FK"
outer-join="auto"/>

</map>

Mapping in ContactMeta

<many-to-one
name="fieldReference"
class="ks.rah.cainfo.db.model.ContactField"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="FIELD_FK"
not-null="false"
/>

And.... in ContactField:

<set
name="meta"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted">

<key
column="FIELD_FK"/>

<one-to-many
class="ks.rah.cainfo.db.model.ContactMeta"/>
</set>


So how could a good code example look for example if you would like to, for a particular InfoContact object, retrieve all the entered values for a particular field? I mean, there should be some adfvantage of using the ternary association, shouldn't there? *s*

public class ContactField implements Serializable {
private Long id;
private String fieldName;
private String fieldHtmlName;
private String htmlInputType;
private int sortOrder;
private Set meta;
private boolean visible;
..
..
}

public class ContactMeta implements Serializable {
private Long id;
private ContactField fieldReference;
private int sortOrder;
private int codeValue;
private String displayValue;
private boolean visible;
..
..
}

public class InfoContact implements Serializable {
private Long id;
private Long user;
private Date entryDate;
private long duration;
private int contactType;
private Map data;
..
..
}

Custom getter/setter names in all objects.

And, how great the HibDocs may be, I also (like a couple of other posters) miss the more extended documentation concerning ternary associations.

Thanks in advance, and I wish all a pleasant 2004!

/Froberg


Top
 Profile  
 
 Post subject: Errata
PostPosted: Fri Jan 09, 2004 8:05 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
I see the little model I tried to draw didn't turn out right. Please ignore it!

/F


Top
 Profile  
 
 Post subject: Follow-up question(s)
PostPosted: Fri Jan 09, 2004 1:02 pm 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
...concerning the section 5.10 in Hibernate2 Reference Documentation, p. 38.

Can anybody tell me what the difference between the two mapping snippets is? Does your coding differ between the two?


And some clarification on my earlier post:

ContactField has a 1:M-rel with ContactMeta ONLY because the field must "know" which options to draw on some UI.

My ternary mapping has a slightly different use: the relation between InfoContact and ContactField is 1:M and ContactField and ContactMeta is also 1:M, and I wish the ternary mapping to mirror this. So the latter 1:M-relation has NOTHING to do with the field-option relation above, but should instead model the options that a user selected for a field in a contact form of som kind.

Sincerely,

/The Cantor


Top
 Profile  
 
 Post subject: Re: Follow-up question(s)
PostPosted: Tue Jan 13, 2004 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
kantorn wrote:
Can anybody tell me what the difference between the two mapping snippets is? Does your coding differ between the two?

Just 2 functional samples. Same technical background.

_________________
Emmanuel


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.