|
I have an entity "Business" and a subclass "FooBusiness". There is another entity "BaseUser" with a subclass "FooUserRegistration"
The entities are annotated with @Inheritance(strategy = InheritanceType.JOINED). Both are using an identity named "id" as UUID string.
Trying to delete the FoouserRegistrations is working. In the same method also the FooBusiness table is deleted.
When trying to delete the FooBusiness an incorrect SQL is produced an exception is thrown from PostgresSQL:
CEST ERROR: column „id“ is not unique at char 114
The reason for this is that Business and FooBusiness both have a column "id".
The following native SQL is generated:
insert into HT_Foo select foo0_.id as id from Foo foo0_ inner join Business foo0_1_ on foo0_.id=foo0_1_.id where id in (select foouserreg1_2_.business_id from FooUserRegistration foouserreg1_ inner join FooUser foouserreg1_1_ on foouserreg1_.id=foouserreg1_1_.id inner join BaseUser foouserreg1_2_ on foouserreg1_.id=foouserreg1_2_.id where foouserreg1_2_.creationDate<'2015-08-28 21:12:01.81');
Correct would be:
insert into HT_Foo select foo0_.id as id from Foo foo0_ inner join Business foo0_1_ on foo0_.id=foo0_1_.id where foo0_.id in (select foouserreg1_2_.business_id from FooUserRegistration foouserreg1_ inner join FooUser foouserreg1_1_ on foouserreg1_.id=foouserreg1_1_.id inner join BaseUser foouserreg1_2_ on foouserreg1_.id=foouserreg1_2_.id where foouserreg1_2_.creationDate<'2015-08-28 21:12:01.81');
I have tracked this down to org.hibernate.hql.spi.id.AbstractTableBasedBulkIdHandler#generateIdInsertSelect There the SQL is produced. Prefixing the where clause with the table alias could fix the issue.
My bugfix for now is to use a create a query with a JQL string directly.
|