here is the documentation of the problem I'm having. I'll try to explain it again. I have an existing database that I'm trying to use hibernate on top of. So I have a schema I'm stuck with. Here is the log output:
16:25:59,492 DEBUG JTATransaction:50 - commit
16:25:59,492 DEBUG SessionImpl:2193 - flushing session
16:25:59,492 DEBUG Cascades:497 - processing cascades for: test.persistence.data.hibernate.Observation
16:25:59,492 DEBUG Cascades:524 - cascading to collection: test.persistence.data.hibernate.Observation.referenceRanges
16:25:59,492 DEBUG Cascades:113 - cascading to saveOrUpdate()
16:25:59,492 DEBUG SessionImpl:1306 - saveOrUpdate() persistent instance
16:25:59,492 DEBUG Cascades:506 - done processing cascades for: test.persistence.data.hibernate.Observation
16:25:59,502 DEBUG Cascades:497 - processing cascades for: test.persistence.data.hibernate.ReferenceRange
16:25:59,502 DEBUG Cascades:524 - cascading to collection: test.persistence.data.hibernate.ReferenceRange.rangeInterpret
ations
16:25:59,502 DEBUG Cascades:113 - cascading to saveOrUpdate()
16:25:59,502 DEBUG SessionImpl:1306 - saveOrUpdate() persistent instance
16:25:59,502 DEBUG Cascades:506 - done processing cascades for: test.persistence.data.hibernate.ReferenceRange
16:25:59,502 DEBUG SessionImpl:2321 - Flushing entities and processing referenced collections
16:25:59,502 DEBUG WrapVisitor:76 - Wrapped collection in role: test.persistence.data.hibernate.Observation.referenceRan
ges
16:25:59,502 DEBUG AbstractEntityPersister:278 - test.persistence.data.hibernate.Observation.referenceRanges is dirty
16:25:59,512 DEBUG SessionImpl:2415 - Updating entity: [test.persistence.data.hibernate.Observation#155]
16:25:59,512 DEBUG Versioning:26 - Incrementing: 2004-02-16 16:25:59.442 to 2004-02-16 16:25:59.512
16:25:59,512 DEBUG SessionImpl:2768 - Collection found: [test.persistence.data.hibernate.Observation.referenceRanges#155
], was: [<unreferenced>]
16:25:59,512 DEBUG WrapVisitor:76 - Wrapped collection in role: test.persistence.data.hibernate.ReferenceRange.rangeInte
rpretations
16:25:59,512 DEBUG SessionImpl:2415 - Updating entity: [test.persistence.data.hibernate.ReferenceRange#TwistedRangeType4
]
16:25:59,512 DEBUG SessionImpl:2768 - Collection found: [test.persistence.data.hibernate.ReferenceRange.rangeInterpretat
ions#TwistedRangeType4], was: [<unreferenced>]
16:25:59,512 DEBUG SessionImpl:2664 - Processing unreferenced collections
16:25:59,522 DEBUG SessionImpl:2678 - Scheduling collection removes/(re)creates/updates
16:25:59,522 DEBUG SessionImpl:2217 - Flushed: 2 insertions, 2 updates, 0 deletions to 3 objects
16:25:59,522 DEBUG SessionImpl:2222 - Flushed: 2 (re)creations, 0 updates, 1 removals to 2 collections
16:25:59,522 DEBUG Printer:75 - listing entities:
16:25:59,522 DEBUG Printer:82 - test.persistence.data.hibernate.RangeInterpretation{observation=Observation#155, referen
ceRange=ReferenceRange#TwistedRangeType4, description=broken4, interpretationId=208}
16:25:59,522 DEBUG Printer:82 - test.persistence.data.hibernate.Observation{observationId=155, referenceRanges=[Referenc
eRange#TwistedRangeType4], interpretation=My Interpretation, effectiveTime=null, observationComponentsByObservationId=nu
ll, targetSite=Toe, observationComponentsByParentObservationId=null, observationMethod=Taste, labResult=LabResult#5, ver
sion=16 February 2004 16:25:59}
16:25:59,522 DEBUG Printer:82 - test.persistence.data.hibernate.ReferenceRange{observation=Observation#155, rangeType=Tw
istedRangeType4, rangeInterpretations=[RangeInterpretation#208]}
16:25:59,532 DEBUG SessionImpl:2258 - executing flush
16:25:59,532 DEBUG EntityPersister:454 - Inserting entity: [test.persistence.data.hibernate.Observation#155]
16:25:59,532 DEBUG EntityPersister:455 - Version: 2004-02-16 16:25:59.442
16:25:59,532 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
16:25:59,532 DEBUG SQL:223 - insert into OBSERVATION (OBSERVATION_VERSION_TIMESTAMP, EFFECTIVE_TIME, INTERPRETATION, OBS
ERVATION_METHOD, TARGET_SITE, CLINICAL_ACT_ID, OBSERVATION_ID) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into OBSERVATION (OBSERVATION_VERSION_TIMESTAMP, EFFECTIVE_TIME, INTERPRETATION, OBSERVATION_METHOD, T
ARGET_SITE, CLINICAL_ACT_ID, OBSERVATION_ID) values (?, ?, ?, ?, ?, ?, ?)
16:25:59,532 DEBUG BatcherImpl:227 - preparing statement
16:25:59,542 DEBUG EntityPersister:389 - Dehydrating entity: [test.persistence.data.hibernate.Observation#155]
16:25:59,542 DEBUG TimestampType:46 - binding '16 February 2004 16:25:59' to parameter: 1
16:25:59,542 DEBUG TimestampType:41 - binding null to parameter: 2
16:25:59,542 DEBUG StringType:46 - binding 'My Interpretation' to parameter: 3
16:25:59,542 DEBUG StringType:46 - binding 'Taste' to parameter: 4
16:25:59,542 DEBUG StringType:46 - binding 'Toe' to parameter: 5
16:25:59,542 DEBUG Cascades:341 - id unsaved-value strategy NULL
16:25:59,552 DEBUG LongType:46 - binding '5' to parameter: 6
16:25:59,552 DEBUG LongType:46 - binding '155' to parameter: 7
16:25:59,562 DEBUG EntityPersister:454 - Inserting entity: [test.persistence.data.hibernate.RangeInterpretation#208]
16:25:59,562 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
16:25:59,562 DEBUG BatcherImpl:240 - closing statement
16:25:59,562 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
16:25:59,572 DEBUG SQL:223 - insert into RANGE_INTERPRETATION (DESCRIPTION, OBSERVATION_ID, RANGE_TYPE, INTERPRETATION_I
D) values (?, ?, ?, ?)
Hibernate: insert into RANGE_INTERPRETATION (DESCRIPTION, OBSERVATION_ID, RANGE_TYPE, INTERPRETATION_ID) values (?, ?, ?
, ?)
16:25:59,572 DEBUG BatcherImpl:227 - preparing statement
16:25:59,572 DEBUG EntityPersister:389 - Dehydrating entity: [test.persistence.data.hibernate.RangeInterpretation#208]
16:25:59,572 DEBUG StringType:46 - binding 'broken4' to parameter: 1
16:25:59,582 DEBUG LongType:46 - binding '155' to parameter: 2
16:25:59,582 DEBUG StringType:46 - binding 'TwistedRangeType4' to parameter: 3
16:25:59,582 DEBUG LongType:46 - binding '208' to parameter: 4
16:25:59,592 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
16:25:59,592 DEBUG BatcherImpl:240 - closing statement
16:25:59,592 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: ORA-28115: policy with check option violation
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
The check exception is a result of the range interpretation insert occurring before the reference range has been inserted.
here are the 3 classes in question: observation, reference_range and range_interpretation in order:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="test.persistence.data.hibernate.Observation"
table="OBSERVATION"
optimistic-lock="version"
>
<id
name="observationId"
type="java.lang.Long"
column="OBSERVATION_ID"
>
<generator class="sequence">
<param name="sequence">OBSERVATION_ID_SEQ</param>
</generator>
</id>
<version
column="OBSERVATION_VERSION_TIMESTAMP"
name="version"
type="java.util.Date"
/>
<property
name="effectiveTime"
type="java.util.Date"
column="EFFECTIVE_TIME"
/>
<property
name="interpretation"
type="java.lang.String"
column="INTERPRETATION"
length="180"
/>
<property
name="observationMethod"
type="java.lang.String"
column="OBSERVATION_METHOD"
length="180"
/>
<property
name="targetSite"
type="java.lang.String"
column="TARGET_SITE"
length="180"
/>
<set name="referenceRanges"
table="reference_range"
lazy="true"
cascade="all"
inverse="false"
>
<key>
<column name="OBSERVATION_ID" />
</key>
<one-to-many class="test.persistence.data.hibernate.ReferenceRange"
/>
</set>
<!-- associations -->
<!-- bi-directional many-to-one association to LabResult -->
<many-to-one
name="labResult"
class="test.persistence.data.hibernate.LabResult"
not-null="true"
>
<column name="CLINICAL_ACT_ID" />
</many-to-one>
<!-- bi-directional one-to-many association to ObservationComponent -->
<set
name="observationComponentsByObservationId"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="OBSERVATION_ID" />
</key>
<one-to-many
class="test.persistence.data.hibernate.ObservationComponent"
/>
</set>
<!-- bi-directional one-to-many association to ObservationComponent -->
<set
name="observationComponentsByParentObservationId"
lazy="true"
inverse="true"
>
<key>
<column name="PARENT_OBSERVATION_ID" />
</key>
<one-to-many
class="test.persistence.data.hibernate.ObservationComponent"
/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="test.persistence.data.hibernate.ReferenceRange"
table="REFERENCE_RANGE"
>
<id
name="rangeType"
column="RANGE_TYPE"
type="java.lang.String"
length="20"
>
<generator class="assigned"/>
</id>
<!-- bi-directional many-to-one association to Observation -->
<many-to-one
name="observation"
class="test.persistence.data.hibernate.Observation"
>
<column name="OBSERVATION_ID" />
</many-to-one>
<!-- associations -->
<!-- bi-directional one-to-many association to RangeInterpretation -->
<set
name="rangeInterpretations"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="RANGE_TYPE" />
</key>
<one-to-many
class="test.persistence.data.hibernate.RangeInterpretation"
/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="test.persistence.data.hibernate.RangeInterpretation"
table="RANGE_INTERPRETATION"
>
<id
name="interpretationId"
type="java.lang.Long"
column="INTERPRETATION_ID"
>
<generator class="sequence">
<param name="sequence">INTERPRETATION_ID_SEQ</param>
</generator>
</id>
<property
name="description"
type="java.lang.String"
column="DESCRIPTION"
length="180"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to ReferenceRange -->
<many-to-one
name="observation"
class="test.persistence.data.hibernate.Observation"
not-null="true"
>
<column name="OBSERVATION_ID" />
</many-to-one>
<!-- associations -->
<!-- bi-directional many-to-one association to ReferenceRange -->
<many-to-one
name="referenceRange"
class="test.persistence.data.hibernate.ReferenceRange"
not-null="true"
>
<column name="RANGE_TYPE" />
</many-to-one>
</class>
</hibernate-mapping>
Here are the 3 tables.
SQL> desc clinical_user.observation
Name Null? Type
----------------------------------------- -------- ----------------------------
OBSERVATION_ID NOT NULL NUMBER(10)
CLINICAL_ACT_ID NOT NULL NUMBER(10)
EFFECTIVE_TIME TIMESTAMP(6)
INTERPRETATION VARCHAR2(180)
OBSERVATION_METHOD VARCHAR2(180)
TARGET_SITE VARCHAR2(180)
OBSERVATION_VERSION_TIMESTAMP TIMESTAMP(6)
SQL> desc clinical_user.reference_range
Name Null? Type
----------------------------------------- -------- ----------------------------
RANGE_TYPE NOT NULL VARCHAR2(20)
OBSERVATION_ID NOT NULL NUMBER(10)
SQL> desc clinical_user.range_interpretation
Name Null? Type
----------------------------------------- -------- ----------------------------
INTERPRETATION_ID NOT NULL NUMBER(10)
OBSERVATION_ID NOT NULL NUMBER(10)
RANGE_TYPE NOT NULL VARCHAR2(20)
DESCRIPTION VARCHAR2(180)
INTERPRETATION_ID uses a sequence for a key as does OBSERVATION_ID on the Observation table.
RANGE_TYPE/OBSERVATION_ID is a composite key for uniqueness in the REFERENCE_RANGE table and is a FK on the RANGE_INTERPRETATION.
Nasty, I know but the goal was to compare multiple O/R tools. Right now, I'm struggling to store a graph of this using hibernate.
Thanks for any help.