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: one-to-one formula missing?
PostPosted: Tue Apr 08, 2008 6:48 am 
Newbie

Joined: Tue Apr 08, 2008 6:24 am
Posts: 8
Hibernate version: 1.2.1

This problem is really giving my a headache, can anyone help?

The structure of the db is as follows.

I have a table (inc_incident) with 2 foreign keys (inc_ref) and to the table (attendee) which is a one to one.

But the difficulty arises because attendee table also contains one-to-many data. in that it contains an identity key (ia_serial) and a foreign key (ia_in_ref) back to the incident table.

Therefore the attendee table contains one-to-one rows and one-to-many rows. Therefore what I did was to add a type column (ia_type to attendee to filter, where type=1 for person in charge (fk), type=2 for person in charge finally and type=3 for the list of attendees on an incident.

Now I can get the list of attendees to work fine using discriminators. See below.

<class name="Incident" table="in_cidents" optimistic-lock="dirty" dynamic-update="true" dynamic-insert="true">
<!-- incident number/primary key -->
<id name="Id" type="Int32" unsaved-value="null">
<column name="in_ref" sql-type="int" not-null="true" index="idx_in_ref"/>
<generator class="assigned"/>
</id>
<!--<one-to-one name="PersonInChargeAtFirst" class="PersonInChargeAtFirst" cascade="all-delete-orphan" ></one-to-one>
<one-to-one name="PersonInChargeFinal" class="PersonInChargeFinal" cascade="all-delete-orphan"/>-->

<!--<many-to-one name="PersonInChargeAtFirst" class="PersonInChargeAtFirst" column="in_ref" not-found="ignore" cascade="all-delete-orphan" insert="true" update="true"/>-->
<many-to-one name="PersonInChargeFinal" class="PersonInChargeFinal" not-found="ignore" insert="true" update="true"
unique="true"
cascade="all">
<column name="in_ref" sql-type="int"/>
</many-to-one>
<bag name="IncidentAttendings" inverse="true" lazy="false" cascade="all-delete-orphan" where="ia_type=3">
<key column ="ia_in_ref" />
<one-to-many class="SeniorOfficer"/>
</bag>
</class>
<class name="PersonInChargeFinal" table="ia_incident_attend" where="ia_type=2" discriminator-value="2" optimistic-lock="dirty" dynamic-update="true" dynamic-insert="true">
<id name="Id" type="Int32" unsaved-value="null">
<column name="ia_in_ref" sql-type="int" not-null="true" index="idx_ia_in_ref"/>
<generator class="foreign">
<param name="property">Parent</param>
</generator>
</id>

<discriminator column="ia_type" type="string" insert="true" force="true" not-null="true"/>
</class>
<class name="SeniorOfficer" table="ia_incident_attend" discriminator-value="3" optimistic-lock="dirty" dynamic-update="true" dynamic-insert="true">
<id name="Id" type="Int32">
<column name="ia_serial" sql-type="int" not-null="false" index="idx_ia_serial"/>
<generator class="identity"/>
</id>

<discriminator column="ia_type" type="string" insert="true" not-null="true"/>

<many-to-one name="Parent" class="Incident" >
<column name="ia_in_ref" sql-type="int" not-null="true" index="idx_ia_in_ref"/>
</many-to-one>
</class>

But I have tried one-to-one mapping and many-to-one mappings for other two relationships and can't figure it out. Thought I could use formulas on one-to-one but this isn't present .

Hope I have explained it ok


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.