-->
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.  [ 13 posts ] 
Author Message
 Post subject: entities before components
PostPosted: Thu Feb 12, 2004 2:06 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
Can you explain why entities are processed before components?

_________________
voe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
? What do you mean by that


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
components have no life out of their respective entities. They are bound

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 2:21 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
emmanuel wrote:
components have no life out of their respective entities. They are bound


i guess i would've expected that when a class is persisted that it's composite elements would immediately follow and then any entities associated with the class. that doesn't seem to be what's happening? a brief code dive suggests the decision is a conscious one and i'm trying to determine why.

my particalar problem has to do with a class that has a component collection and also a set of entities that depend on the persisting of that component collection before the entities are saved.

_________________
voe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 5:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please clarify your problem. Hibernate does SQL queries in the right order no matter it is an entity or a component.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: sorry it took so long
PostPosted: Mon Feb 16, 2004 5:36 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
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.

_________________
voe


Top
 Profile  
 
 Post subject: And here's the code to populate the graph
PostPosted: Mon Feb 16, 2004 5:39 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
ClinicalAct act = (ClinicalAct) iter.next();
if (act != null && act.getLabResult() != null ) {
if (act.getLabResult().getClinicalActId().equals(new Long(5))) {
loadClinicalActSlow(act,null);
Observation obs = new Observation();
obs.setInterpretation("My Interpretation");
obs.setTargetSite("Toe");
obs.setObservationMethod("Taste");
obs.setLabResult(act.getLabResult());
Observation parentObservation = findParentObservation(act.getLabResult());

if (parentObservation != null)
{
//add this observation to the component list of the parent
//observation
//ObservationComponent obc = new ObservationComponent();
//obc.setPriorityNum(new Integer(1));
//obc.setObservationByObservationId(obs);
//obc.setObservationByParentObservationId(parentObservation);

//Set obComps = parentObservation.getObservationComponentsByObservationId();
//obComps.add(obc);
//obs.setObservationComponentsByObservationId(obComps);
//parentObservation.getObservationComponentsByParentObservationId().add(obc);


}
else
throw new Exception("crap");


ReferenceRange rr = new ReferenceRange();
rr.setRangeType("TwistedRangeType4");
rr.setObservation(obs);

RangeInterpretation ri = new RangeInterpretation();
ri.setDescription("broken4");
ri.setReferenceRange(rr);
ri.setObservation(obs);
Set riSet = new HashSet();
riSet.add(ri);
rr.setRangeInterpretations(riSet);

Set rrSet = new HashSet();
rrSet.add(rr);
obs.setReferenceRanges(rrSet);

VPDTestFacade.saveObservation(obs,"BW");

}

_________________
voe


Top
 Profile  
 
 Post subject: Finally, ,my question
PostPosted: Mon Feb 16, 2004 5:41 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
Why does the range_interpretation collection get inserted before the reference_range collection. If it was walking down the tree, it would seem to go from observation to reference_range to range_interpretation...

Thanks.

_________________
voe


Top
 Profile  
 
 Post subject: composite-id saving
PostPosted: Mon Feb 16, 2004 6:13 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
Ok. It looks like the problem is that it's not recognizing that my composite-id is new and needs to be saved. I'm not sure how to use the unsaved-value declaration is in this case?

_________________
voe


Top
 Profile  
 
 Post subject: unsaved-value=any
PostPosted: Mon Feb 16, 2004 6:25 pm 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
ok. the only work around i could find for this problem was setting unsaved-value = "any", after reverting to using a composite-id:

<class
name="test.persistence.data.hibernate.ReferenceRange"
table="REFERENCE_RANGE"
>

<composite-id unsaved-value="any">
<key-property
name="rangeType"
column="RANGE_TYPE"
type="java.lang.String"
length="20"
/>
<!-- bi-directional many-to-one association to Observation -->
<key-many-to-one
name="observation"
class="test.persistence.data.hibernate.Observation"

>
<column name="OBSERVATION_ID" />
</key-many-to-one>
</composite-id>


<!-- associations -->
<!-- bi-directional one-to-many association to RangeInterpretation -->
<set
name="rangeInterpretations"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="RANGE_TYPE" />
<column name="OBSERVATION_ID" />
</key>
<one-to-many
class="test.persistence.data.hibernate.RangeInterpretation"
/>
</set>

</class>


However doesn't this mean that an update will fail of the graph if the observation id/range_type already exists? I'm sure there must be other workarounds?

_________________
voe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a quick look at the reference guide and the FAQ, there are some explainations and solutions to that (composite-id and unsaved-value)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: thanks for the replay --- interceptor
PostPosted: Tue Feb 17, 2004 11:08 am 
Newbie

Joined: Thu Feb 12, 2004 2:04 pm
Posts: 8
Are you suggesting that I try the isUnsaved() interceptor. What do I do? Use a flag in the object and then use the interceptor to tell hibernate the right thing to do? Sounds like an approach...

_________________
voe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 11:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually I prefer using <version unsaved-value> if I can because it's strictly equivalent to <id unsaved-value

_________________
Emmanuel


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