Hi All,
I have an entity with a map inside it. (Mapping to follow).
In a web app I have been using the entity with no problems. I have recently added a new action that loads the entity, but in this action (and not the other action!) when I load the entity it automatically deletes all from the mapped table!
I have recently changed the mapping from a single object to an abstract object with two empty subclasses. (This was to implement an auto-save feature, where you can save an entity in the background, and then do a proper save. If the app is shut down before you do a proper save, the app will see the autosave version and prompt to recover.)
The above works fine, the discriminator is working fine etc. The problem occurs when I try to load the autosaved version and copy its fields into the 'proper' version. Even without loading the autosave version, just loading the proper version will delete one of the maps.
This is the sql executed when the object is loaded:
-----the main entity Hibernate: select //snip// from Assessment assessment0_ where assessment0_.AssessmentId=?
-- HERE IS THE MAP BEING LOADED Hibernate: select //snip// from AssessedRisk assessedri0_ where assessedri0_.AssessmentId=?
-- another map, this one is not affected... Hibernate: select //snip// from Answer answermap0_ where answermap0_.AssessmentID=?
--another map Hibernate: select //snip// from InterventionDecision interventi0_, InterventionProgram interventi1_, InterventionCategory interventi2_ where interventi0_.AssessmentID=? and interventi0_.InterventionProgramID=interventi1_.InterventionProgramId(+) and interventi1_.InterventionCategoryID=interventi2_.InterventionCategoryId(+) order by interventi0_.DisplaySequenceNum
--yet another map Hibernate: select //snip// from Interview interviewm0_ where interviewm0_.AssessmentId=? order by interviewm0_.InterviewDate
--- ????? WHY IS THIS HAPPENING? Hibernate: delete from AssessedRisk where AssessmentId=?
Here is the mapping:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="au.gov.sa.dcs.ornirlocal.assessment.AbstractAssessmentEntity" table="Assessment" discriminator-value=" " polymorphism="explicit">
<composite-id name="assessmentPK" class="au.gov.sa.dcs.ornir.primarykey.AssessmentPK"> <key-property name="value" column="AssessmentId" type="long" /> </composite-id>
<discriminator column="AssessmentTypeCode" type="string" force="true" />
<version name="versionNumAsLong" column="VersionNum" type="long" /> //SNIP//
<map name="answerMap" table="Answer"> <key> <column name="AssessmentID" not-null="true" /> </key> <composite-index class="au.gov.sa.dcs.ornir.primarykey.SurveyPartPK"> <key-property name="value" column="SurveyPartId" type="long" /> </composite-index> <composite-element class="au.gov.sa.dcs.ornirlocal.assessment.AnswerValueImpl"> <nested-composite-element name="booleanValue" class="au.gov.sa.justice.framework.entity.datatype.BooleanDataType"> <property name="valueAsString" column="AnswerInd" type="string" /> </nested-composite-element> <nested-composite-element name="answerValueLargeObjectPK" class="au.gov.sa.justice.commonlargeobjectlocal.largeobject.LargeObjectPK"> <property name="value" column="AnswerLargeObjectId" type="long" /> </nested-composite-element> <nested-composite-element name="textValue" class="au.gov.sa.dcs.ornir.survey.StringAnswerDataType"> <property name="value" column="AnswerText" type="string" /> </nested-composite-element> </composite-element> </map> <map name="assessedRiskMap" table="AssessedRisk"> <key> <column name="AssessmentId" not-null="true" /> </key> <composite-index class="au.gov.sa.dcs.ornir.primarykey.SurveyPartPK"> <key-property name="value" column="SurveyPartId" type="long" /> </composite-index> <composite-element class="au.gov.sa.dcs.ornir.survey.Risk"> <property name="riskScore" column="RiskScore" type="int" /> <nested-composite-element name="riskLevel" class="au.gov.sa.dcs.ornir.survey.RiskLevel"> <property name="value" column="RiskLevelName" type="string" /> </nested-composite-element> </composite-element> </map>
<!-- the normal assessment entity --> <subclass name="au.gov.sa.dcs.ornirlocal.assessment.AssessmentEntity" discriminator-value="NRML"/>
<!-- the auto-save entity --> <subclass name="au.gov.sa.dcs.ornirlocal.assessment.AssessmentAutoSaveEntity" discriminator-value="AUTO"> <component name="parentAssessmentPK" class="au.gov.sa.dcs.ornir.primarykey.ParentAssessmentPK"> <property name="value" column="ParentAssessmentID" type="long" /> </component> </subclass> </class>
</hibernate-mapping>
In the AbstractAssessmentEntity, I am declaring the maps like this:
private Map<PrimaryKey, AnswerValue> answerMap = new HashMap<PrimaryKey, AnswerValue>(); private Map<PrimaryKey, Risk> assessedRiskMap = new HashMap<PrimaryKey, Risk>();
I used to initialise them in the constructor but moved them up to see if that made a difference.
Any clues??? Sorry for the long post, please request more info if required.
Thanks!!!
|