So, the tests that reproduces the issue is doing a few inserts before the failing deleteAll() call, so there is some additional SQL involved; I will paste the test as well as all generated SQL, and will highlight the relevant bits:
The test code:
final Privilege existingAssociation = getAssociationService().create( new Privilege( randomAlphabetic( 6 ) )
final Role newResource = createNewEntity();
newResource.getPrivileges().add( existingAssociation );
getService().create( newResource );
privilegeService.deleteAll();The SQL:
Hibernate: alter table Principal_Role drop constraint FK71AEF6277BF8AB4A
Hibernate: alter table Principal_Role drop constraint FK71AEF627323F55D9
Hibernate: alter table Role_Privilege drop constraint FK81B4C2287DC9D9CA
Hibernate: alter table Role_Privilege drop constraint FK81B4C22896D682CC
Hibernate: drop table Principal if exists
Hibernate: drop table Principal_Role if exists
Hibernate: drop table Privilege if exists
Hibernate: drop table Role if exists
Hibernate: drop table Role_Privilege if exists
Hibernate: create table Principal (PRINCIPAL_ID bigint generated by default as identity, name varchar(255) not null unique, password varchar(255) not null, primary key (PRINCIPAL_ID))
Hibernate: create table Principal_Role (Principal_PRINCIPAL_ID bigint not null, roles_ROLE_ID bigint not null, primary key (Principal_PRINCIPAL_ID, roles_ROLE_ID), unique (roles_ROLE_ID))
Hibernate: create table Privilege (PRIV_ID bigint generated by default as identity, name varchar(255) not null unique, primary key (PRIV_ID))
Hibernate: create table Role (ROLE_ID bigint generated by default as identity, name varchar(255) not null unique, primary key (ROLE_ID))
Hibernate: create table Role_Privilege (ROLE_ID bigint not null, PRIV_ID bigint not null, primary key (ROLE_ID, PRIV_ID))
Hibernate: alter table Principal_Role add constraint FK71AEF6277BF8AB4A foreign key (roles_ROLE_ID) references Role
Hibernate: alter table Principal_Role add constraint FK71AEF627323F55D9 foreign key (Principal_PRINCIPAL_ID) references Principal
Hibernate: alter table Role_Privilege add constraint FK81B4C2287DC9D9CA foreign key (PRIV_ID) references Privilege
Hibernate: alter table Role_Privilege add constraint FK81B4C22896D682CC foreign key (ROLE_ID) references Role
Hibernate: delete from Privilege
Hibernate: delete from Role
Hibernate: delete from Principal
Hibernate: insert into Privilege (PRIV_ID, name) values (null, ?)
Hibernate: insert into Role (ROLE_ID, name) values (null, ?)
Hibernate: insert into Role_Privilege (ROLE_ID, PRIV_ID) values (?, ?)
Hibernate: delete from PrivilegeHibernate: alter table Principal_Role drop constraint FK71AEF6277BF8AB4AHibernate: alter table Principal_Role drop constraint FK71AEF627323F55D9Hibernate: alter table Role_Privilege drop constraint FK81B4C2287DC9D9CAHibernate: alter table Role_Privilege drop constraint FK81B4C22896D682CCHibernate: drop table Principal if exists
Hibernate: drop table Principal_Role if exists
Hibernate: drop table Privilege if exists
Hibernate: drop table Role if exists
Hibernate: drop table Role_Privilege if exists
The exception:
org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK81B4C2287DC9D9CA: PUBLIC.ROLE_PRIVILEGE FOREIGN KEY(PRIV_ID) REFERENCES PUBLIC.PRIVILEGE(PRIV_ID)"; SQL statement:
delete from Privilege [23503-164]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:398)
at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:415)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:291)
at org.h2.table.Table.fireConstraints(Table.java:862)
at org.h2.table.Table.fireAfterRow(Table.java:879)
at org.h2.command.dml.Delete.update(Delete.java:99)
at org.h2.command.CommandContainer.update(CommandContainer.java:73)
at org.h2.command.Command.executeUpdate(Command.java:226)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 65 more
Hope this makes debugging and solving the issue easier.
Thanks.
Eugen.
> h2-database+unsubscribe@googlegroups.com.