Please can anyone help with this problem.
Within a session, I am deleting several rows from a table (no foreign keys), then inserting rows to the same table. I start a transaction prior to doing the deletes, and do not close it until the inserts are done.
The deletes work fine, but as soon as I try to insert i get the following message.
16:28:38,249 WARN JDBCExceptionReporter:71 - SQL Error: 1, SQLState: 23000
16:28:38,249 ERROR JDBCExceptionReporter:72 - ORA-00001: unique constraint (GPMD
.METRICS_UK_1) violated
16:28:38,249 WARN JDBCExceptionReporter:71 - SQL Error: 1, SQLState: 23000
16:28:38,249 ERROR JDBCExceptionReporter:72 - ORA-00001: unique constraint (GPMD
.METRICS_UK_1) violated
16:28:38,249 ERROR AbstractFlushingEventListener:300 - Could not synchronize dat
abase state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC bat
ch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.j
ava:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp
er.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:
202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractF
=======================================
The PK for this table is a sequence - column is 'METRICS_ID' and the sequence is 'Metrics_seq' - see mapping file below.
How could there be this error happen when the PK is generated?
>>>>>>>>>> mapping file >>>>>>>>>>>>>>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
OR MApping between METRICS AND Metrics.class
-->
<class name="com.gpmd.persistence.metrics.Metrics"
lazy="false"
table="METRICS">
<!--
<cache usage="read-write" />
-->
<id name="metricsId"
type="integer"
unsaved-value="null">
<column name="METRICS_ID" length="40" />
<generator class="sequence">
<param name="sequence">Metrics_seq</param>
</generator>
</id>
<property name="footprintNumber" type="string">
<column name="FOOTPRINT_NUMBER" length="30" not-null="true" />
</property>
<property name="metricsCode" type="string">
<column name="METRICS_CODE" length="24" not-null="true"/>
</property>
<property name="metricsDescription" type="string">
<column name="METRICS_DESCRIPTION" length="80" not-null="true" />
</property>
<property name="metricsIsCompleted" type="float">
<column name="METRICS_IS_COMPLETED" length="1" not-null="true" />
</property>
<property name="metricsBaselineDuration" type="float">
<column name="METRICS_BASELINE_DURATION" length="10" not-null="true" />
</property>
<property name="metricsActualDuration" type="float">
<column name="METRICS_ACTUAL_DURATION" length="10" not-null="false" />
</property>
<property name="metricsTargetStartDate" type="date">
<column name="METRICS_TARGET_START_DATE" length="7" not-null="false" />
</property>
<property name="metricsTargetEndDate" type="date">
<column name="METRICS_TARGET_END_DATE" length="7" not-null="false" />
</property>
<property name="metricsActualStartDate" type="date">
<column name="METRICS_ACTUAL_START_DATE" length="7" not-null="false" />
</property>
<property name="metricsActualEndDate" type="date">
<column name="METRICS_ACTUAL_END_DATE" length="7" not-null="false" />
</property>
<property name="metricsIsMilestone" type="float">
<column name="METRICS_IS_MILESTONE" length="1" not-null="true" />
</property>
<property name="metricsIsPq" type="float">
<column name="METRICS_IS_PQ" length="1" not-null="true" />
</property>
<property name="metricsMilestoneCode" type="string">
<column name="METRICS_MILESTONE_CODE" length="24" not-null="false" />
</property>
<property name="metricsForecastDuration" type="float">
<column name="METRICS_FORECAST_DURATION" length="10" not-null="false" />
</property>
<property name="metricsForecastStartDate" type="date">
<column name="METRICS_FORECAST_START_DATE" length="7" not-null="false" />
</property>
<property name="metricsForecastEndDate" type="date">
<column name="METRICS_FORECAST_END_DATE" length="7" not-null="false" />
</property>
</class>
</hibernate-mapping>
===============================
Hibernate version is: 3.1 and Oracle 9.
===============================
The generated SQL (show_sql=true):
===================================
Hibernate:
/* insert com.gpmd.persistence.metrics.Metrics
*/ insert
into
METRICS
(FOOTPRINT_NUMBER, METRICS_CODE, METRICS_DESCRIPTION, METRICS_IS_COM
PLETED, METRICS_BASELINE_DURATION, METRICS_ACTUAL_DURATION, METRICS_TARGET_START
_DATE, METRICS_TARGET_END_DATE, METRICS_ACTUAL_START_DATE, METRICS_ACTUAL_END_DA
TE, METRICS_IS_MILESTONE, METRICS_IS_PQ, METRICS_MILESTONE_CODE, METRICS_FORECAS
T_DURATION, METRICS_FORECAST_START_DATE, METRICS_FORECAST_END_DATE, METRICS_ID)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
=====================================
Any help greatly appreciated...
|