-->
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: Persisting trouble with ternary
PostPosted: Fri Jan 16, 2004 4:52 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi.

I posted a question earlier about ternary associations, but...

The prblem is I can't make the code work. I have three classes;
InfoContact, ContactField and ContactMeta. They all should be associated
by a fourth class, ContactDataNode. The InfoContact object holds a List
of ContactDataNode objects. ContactField and ContactMeta also holds a Set of
ContactDataNodeObjects. I assume you have to "inform" these
objects of the ternary association class in order
to be able to pose HQL-questions to ContactDataNode. Is thei correct?
Here is the appropriate (I hope) mapping snippets:

=================================================
<class
name="ks.rah.cainfo.db.model.InfoContact"
table="CONTACT"
dynamic-update="false"
dynamic-insert="false">
..
..
<list
name="data"
lazy="true"
inverse="true"
cascade="save-update">

<key column="CONTACT_FK"/>

<index column="I"/>

<one-to-many class="ks.rah.cainfo.db.model.ContactDataNode"/>
</list>
...
</class>
==================================================
<class
name="ks.rah.cainfo.db.model.ContactField"
table="CONTACT_FIELD"
dynamic-update="false"
dynamic-insert="false"
>
..
..
<set
name="answers"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted">

<key column="ANSWERFIELD_FK" />
<one-to-many class="ks.rah.cainfo.db.model.ContactDataNode" />
</set>
...
</class>
==================================================
<class
name="ks.rah.cainfo.db.model.ContactMeta"
table="CONTACT_META"
dynamic-update="false"
dynamic-insert="false">
..
..
<set
name="answers"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted">

<key column="META_FK"/>
<one-to-many class="ks.rah.cainfo.db.model.ContactDataNode"/>
</set>
..
</class>
==================================================
<class
name="ks.rah.cainfo.db.model.ContactDataNode"
table="DATANODE"
dynamic-update="false"
dynamic-insert="false">

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null">
<generator class="native">
</generator>
</id>

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

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

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

</class>
=====================================================
I have tried to add three add-methods to ContactDataNode

public ContactDataNode addContact(InfoContact contact) {
this.setContact( contact );
contact.getData().add(this);
return this;
}

public ContactDataNode addValue(ContactMeta meta) {
this.setValue( meta );
meta.getAnswers().add(this);
return this;
}

public ContactDataNode addField(ContactField field) {
this.setField( field );
field.getAnswers().add(this);
return this;
}

These three I have put in InfoContact:

public void addData(ContactField field, ContactMeta value) {
ContactDataNode node = new ContactDataNode();
node.addField(field).addValue(value);
this.getData().add(node);
}

However, when i repeatedly invoke this method, the List of
datanodes is constantly '1', and when I send it to a business
object for persistence to database, only one entry is created
in the ContactDataNode-table.

I've also tried the following code in my application:
..
..

InfoContact contact = new InfoContact();
ContactField currentField = null;
ContactMeta currentValue = null;
ArrayList data = new ArrayList();
..
..


currentField = HibernateGetField(argument); //Codescetch:this works!
currentValue = HibbernateGetValue(anotherArgument); //Codescetch:this works too!
data.add( new ContactDataNode(null, contact, currentField, currentValue );

currentField = HibernateGetField(argument2); //Codescetch:this works!
currentValue = HibbernateGetValue(anotherArgument2); //Codescetch:this works too!
data.add( new ContactDataNode(null, contact, currentField, currentValue );

contact.setData(data);
contactBusinessObject.create(contact);
..

Now nothing is persisted to ContactDataNode-table, but the InfoContact is persisted.

What am I doing wrong?

Thanks in advance!

/F


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.