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) )
|