-->
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.  [ 2 posts ] 
Author Message
 Post subject: Genral problem with composite-id, many-to-one and foreign ke
PostPosted: Wed Jan 04, 2006 1:43 pm 
Newbie

Joined: Thu Dec 29, 2005 5:57 pm
Posts: 5
Hi,

unfortunately I didn't found a solution for a basically question how does relationships or better the many-to-one element look like if you use <composite-id>s.

The following mapping was firstly created with Hibernate Tool...and looks now like this:

<class name="Field" table="fld_field">
<composite-id name="oid" class="myorg.as.jlibs.oid.Oid">
<key-property name="high" type="long" column="fld_oid_high" />
<key-property name="low" type="long" column="fld_oid_low" />
</composite-id>

<many-to-one name="parent" class="Field" fetch="select">
<column name="fld_parent_high" />
<column name="fld_parent_low" />
</many-to-one>

<component name="parentOid" class="myorg.as.jlibs.oid.Oid">
<property name="high" column="fld_parent_high" insert="false" update="false" />
<property name="low" column="fld_parent_low" insert="false" update="false" />
</component>
<property name="timestamp" type="timestamp" update="true">
<column name="fld_ts" length="6" />
</property>
<property name="name" type="string">
<column name="fld_name" />
</property>
<property name="deleted" type="integer">
<column name="fld_deleted" not-null="true" />
</property>
<set name="children" inverse="true">
<key>
<column name="fld_parent_high" />
<column name="fld_parent_low" />
</key>
<one-to-many class="Field" />
</set>
</class>
</hibernate-mapping>

...................................................................................................................................................

My problem is, that I cann't save Field objects
...
Oid oid = new Oid(1L,1L);
Field root = (Field)session.load(Field.class, oid);

Oid newOid = OIDUtil.getOid();
Field newField = new Field( newOid );
newField.setName("Linux");
newField.setDeleted(0);

newField.setParent(root);
session.save(newField);
...
and the log doesn't help much.

I think in the mapping file I also must change the many-to-one element so that hibernate can connect
the columns fld_parent_high and fld_parent_low with the composite class Oid's properties high and low. I think the best solution would be to introduce the class Oid in the many-to-one element.
<many-to-one name="parent" class="Field" fetch="select">
<column name="fld_parent_high" />
<column name="fld_parent_low" />
</many-to-one>

Can help someone?

P.S.
my field table:
That's the table:
CREATE TABLE fld_field(
fld_oid_high BIGINT NOT NULL,
fld_oid_low BIGINT NOT NULL,
fld_parent_high BIGINT,
fld_parent_low BIGINT,fld_name varchar(255) default '',fld_deleted INT default 0 NOT NULL,fld_ts timestamp DEFAULT now,
PRIMARY KEY (fld_oid_high, fld_oid_low),
FOREIGN KEY (fld_parent_high, fld_parent_low) REFERENCES fld_field(fld_oid_high,fld_oid_low) )


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 8:37 pm 
Newbie

Joined: Fri Feb 06, 2004 1:37 pm
Posts: 9
What is the error message? log output?


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