Hi,
I am getting the following exception
Code:
net.sf.hibernate.HibernateException: identifier of an instance of printCondition.domain.PrintCondition altered from [state:A][territory:SA][typeCode:[COBK] - Copy Condition][valueCode:1] to [state:A][territory:SA][typeCode:[COBK] - Copy Condition][valueCode:1]
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2606)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2429)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2422)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2224)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1769)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1536)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1501)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
at printCondition.dao.PrintDB2DAO.getSelectLists(PrintDB2DAO.java:33)
which occurs when I run the following two lines of code -
Code:
selectLists.put(XXPParamTypeCode.COPY_CONDITION, SessionManager.currentSession().find("FROM PrintCondition"));
selectLists.put(XXPParamTypeCode.VERSION_TYPE, SessionManager.currentSession().find("FROM PrintVersionType"));
The first statement executes fine on its own, returning the list and putting it in the hashmap. The stack trace above is actually from the begnning of the second statementsfind method - which appears to somehow trigger a change of the primary key of the objects retrieved from the first statement.
Below are the ampping documents for these two classes -
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="printCondition.domain">
<class name="PrintCondition" table="XXPPARM04" mutable="false">
<composite-id name="id" class="XXPParamKey">
<key-property name="state" type="domain.hibernate.TrimmedString" column="PRSTAT"/>
<key-property name="territory" type="domain.hibernate.TrimmedString" column="PRTERR"/>
<key-property name="typeCode" type="domain.hibernate.XXPParamTypeCodeConverter" column="PRPRMC"/>
<key-property name="valueCode" type="domain.hibernate.TrimmedString" column="PRPRMV"/>
</composite-id>
<property name="typeDescription" type="domain.hibernate.TrimmedString">
<column name="PRDESC" sql-type="char(30)" not-null="true"/>
</property>
<property name="valueDescription" type="domain.hibernate.TrimmedString">
<column name="PRPARM" sql-type="char(40)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
and
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="printCondition.domain">
<class name="PrintVersionType" table="XXPPARM02" mutable="false">
<composite-id name="id" class="XXPParamKey">
<key-property name="state" type="domain.hibernate.TrimmedString" column="PRSTAT"/>
<key-property name="territory" type="domain.hibernate.TrimmedString" column="PRTERR"/>
<key-property name="typeCode" type="domain.hibernate.XXPParamTypeCodeConverter" column="PRPRMC"/>
<key-property name="valueCode" type="domain.hibernate.TrimmedString" column="PRPRMV"/>
</composite-id>
<property name="typeDescription" type="domain.hibernate.TrimmedString">
<column name="PRDESC" sql-type="char(30)" not-null="true"/>
</property>
<property name="valueDescription" type="domain.hibernate.TrimmedString">
<column name="PRPARM" sql-type="char(40)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
A couple of things to note -
1. The XXPPARM02 && XXPPARM04 are just views over the same table. That is why the primary key class and fields are identicial. Unfortunately we did not have the luxury of designing the tables we were mapping to.
2. the 'domain.hibernate.TrimmedString' is simply a UserType that trims the whitespace off CHAR fields before assigning them to a string attribute.
3. the 'domain.hibernate.XXPParamTypeCodeConverter' is a UserType that converts a CHAR field into a constant object. This is actually the field that distinguishes the record sets int he XXPPARM table, and works along the lines - if typeCode is 'X' then we are looking at printConditions, if typeCode is 'Y' then we are lookign at versionTypes.
Can anyone see what I am missing? Cheers,
Colin