Reputation: 1058
I am attempting to my upgrade hibernate libraries for some legacy code and am suddenly getting a unique constraint violation in my unit tests:
java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: unique constraint or index violation; SYS_PK_10344 table: GROUP
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.execute(Unknown Source)
at org.dbunit.database.statement.SimplePreparedStatement.addBatch(SimplePreparedStatement.java:67)
at org.dbunit.database.statement.AutomaticPreparedBatchStatement.addBatch(AutomaticPreparedBatchStatement.java:57)
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:178)
at gov.treas.fms.shared.test.spring.AbstractTransactionalSpringTest.loadDataset(AbstractTransactionalSpringTest.java:551)
... 21 more
Caused by: org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation; SYS_PK_10344 table: GROUP
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.Constraint.getException(Unknown Source)
at org.hsqldb.index.IndexAVLMemory.insert(Unknown Source)
at org.hsqldb.persist.RowStoreAVL.indexRow(Unknown Source)
at org.hsqldb.TransactionManager2PL.addInsertAction(Unknown Source)
at org.hsqldb.Session.addInsertAction(Unknown Source)
at org.hsqldb.Table.insertSingleRow(Unknown Source)
at org.hsqldb.StatementDML.insertSingleRow(Unknown Source)
at org.hsqldb.StatementInsert.getResult(Unknown Source)
at org.hsqldb.StatementDMQL.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 27 more
New library versions
hibernate-commons-annotations: 4.0.5.Final
hibernate-entitymanager: 4.3.10.Final
hibernate-core: 4.3.10.Final
hibernate-jpa-2.1-api: 1.0.0.Final
hsqldb 2.3.4
dbunit: 2.1
Old library versions
hibernate-annotations: 3.4.0.GA
hibernate-commons-annotations: 3.1.0.GA
hibernate-entitymanager: 3.4.0.GA
hibernate-core: 3.3.0.SP1
hsqldb: 1.8.0.7
dbunit: 2.1
The entities look like this:
@AttributeOverrides(
{
@AttributeOverride(name = "id", column = @Column(name = "group_id"))
}
)
public class Group extends AbstractIdentity {
private String description;
private String name;
//getters and setters
}
public abstract class AbstractIdentity {
private long id;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSequenceGenerator")
public Long getId()
{
return id;
}
}
The dbunit data set looks like this:
<dataset>
<group group_id="100"
description="Group description"
name="Group name"/>
</dataset>
It is loaded like this:
IDataSet dataset = constructDbUnitDataset(datasetResourcePath);
DatabaseOperation.INSERT.execute(connection, dataset);
The DataOperation.INSERT line is where I'm getting the exception.
Note that if I run one unit test, it passes. If I run more than one, I get the above exception.
Any help would be much appreciated!!!
Upvotes: 0
Views: 565
Reputation: 953
Compare the DDL gen from prior Hibernate version with the new, you may find different constraints.
Sometimes a prior test leaves data in the DB; run two tests that show the problem and see the data after the first one, ensuring all tables are cleaned up.
Upvotes: 0