Hi,
I have a little problem with Hibernate mapping.
Here is my mapping file :
Code:
<class name="com.foo.service.payroll.grid.PayrollGrid" table="PAYROLL_GRID_EA">
<composite-id name="id" class="com.foo.service.payroll.grid.PayrollGridId">
<key-property name="idGrid" type="java.lang.String">
<column name="ID_GRID" scale="50" precision="0" not-null="true" sql-type="varchar" />
</key-property>
<key-property name="idCompany" type="java.lang.String">
<column name="ID_COMPANY" scale="50" precision="0" not-null="true" sql-type="varchar" />
</key-property>
</composite-id>
<property name="description" type="java.lang.String">
<column name="DESCRIPTION" scale="255" precision="0" not-null="true" sql-type="varchar" />
</property>
. . .
<set name="employeeGrids" table="PAYROLL_GRID_EMPLOYEE_EA" cascade="all">
<key>
<column name="ID_GRID"/>
<column name="ID_COMPANY"/>
</key>
<one-to-many class="com.foo.service.payroll.grid.EmployeeGrid"/>
</set>
</class>
<class name="com.foo.service.payroll.grid.EmployeeGrid" table="PAYROLL_GRID_EMPLOYEE_EA">
<composite-id name="id" class="com.foo.service.payroll.grid.EmployeeGridId">
<key-property name="idGrid" type="java.lang.String">
<column name="ID_GRID" scale="50" precision="0" not-null="true" sql-type="varchar" />
</key-property>
<key-property name="idCompany" type="java.lang.String">
<column name="ID_COMPANY" scale="50" precision="0" not-null="true" sql-type="varchar" />
</key-property>
<key-property name="idEmployee" type="java.lang.String">
<column name="ID_EMPLOYEE" scale="50" precision="0" not-null="true" sql-type="varchar" />
</key-property>
</composite-id>
<property name="status" type="java.lang.String">
<column name="STATUS" scale="10" precision="0" not-null="true" sql-type="varchar" />
</property>
<map name="fieldValues" table="PAYROLL_GRID_EMPLOYEE_FIELD_EA" lazy="false">
<key>
<column name="ID_GRID"/>
<column name="ID_COMPANY"/>
<column name="ID_EMPLOYEE"/>
</key>
<map-key column="FIELD_NAME" type="java.lang.String" length="255"/>
<composite-element class="com.foo.service.payroll.grid.FieldValue">
<property name="textValue" type="java.lang.String">
<column name="TEXT_VALUE" scale="65535" precision="0" not-null="false" sql-type="text" />
</property>
<property name="numValue" type="java.math.BigDecimal">
<column name="NUM_VALUE" scale="30" precision="2" not-null="false" sql-type="decimal" />
</property>
<property name="dateValue" type="java.util.Date">
<column name="DATE_VALUE" scale="19" precision="0" not-null="false" sql-type="datetime" />
</property>
<property name="boolValue" type="java.lang.Boolean">
<column name="BOOL_VALUE" scale="1" precision="0" not-null="false" sql-type="decimal" />
</property>
</composite-element>
</map>
</class>
The main class is the Payroll grid that represent a payroll grid on a period.
It contains a set of EmployeeGrid the second class that represents a employee of the company with his fields ( dynamic fields ).
I managed to
create a PayrollGrid with 2 employees and fields and it's well inserted in the DB.
But when I try to
update the created PayrollGrid, i got this Hibernate Exception :
Code:
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1026)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.foo.hibernate.PersistentObjectDAO.update(PersistentObjectDAO.java:136)
I test it removing the employeeGrids set mapping and the update works good. So the problem is when updating the set of EmployeeGrid or the map of fieldValues in each EmployeeGrid...
Does any one can help me ?