HHH-15115 Deleting an entity with Joined inheritance and default schema set is throwing and error

This commit is contained in:
Andrea Boriero 2022-03-11 08:56:51 +01:00 committed by Yoann Rodière
parent 83b6e6e3d5
commit c3cefd74ca
5 changed files with 128 additions and 4 deletions

View File

@ -72,7 +72,7 @@ public abstract class AbstractCteValuesListBulkIdHandler extends
"HT_" + StringHelper.unquote( persister.getTableName(), jdbcEnvironment.getDialect() )
).render();
return persister.getFactory().getSqlStringGenerationContext().format(
return persister.getFactory().getSqlStringGenerationContext().formatWithoutDefaults(
new QualifiedTableName(
Identifier.toIdentifier( catalog ),
Identifier.toIdentifier( schema ),

View File

@ -112,7 +112,7 @@ public class GlobalTemporaryTableBulkIdStrategy
context.dropStatements.add( buildIdTableDropStatement( idTable, sqlStringGenerationContext ) );
}
final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() );
final String renderedName = sqlStringGenerationContext.formatWithoutDefaults( idTable.getQualifiedTableName() );
return new IdTableInfoImpl( renderedName );
}

View File

@ -119,7 +119,7 @@ public class LocalTemporaryTableBulkIdStrategy
context.dropStatements.add( dropStatement );
}
return new IdTableInfoImpl(
sqlStringGenerationContext.format( idTable.getQualifiedTableName() ),
sqlStringGenerationContext.formatWithoutDefaults( idTable.getQualifiedTableName() ),
buildIdTableCreateStatement( idTable, metadata, sqlStringGenerationContext ),
dropStatement
);

View File

@ -127,7 +127,7 @@ public class PersistentTableBulkIdStrategy
MetadataImplementor metadata,
PreparationContextImpl context,
SqlStringGenerationContext sqlStringGenerationContext) {
final String renderedName = sqlStringGenerationContext.format( idTable.getQualifiedTableName() );
final String renderedName = sqlStringGenerationContext.formatWithoutDefaults( idTable.getQualifiedTableName() );
context.creationStatements.add( buildIdTableCreateStatement( idTable, metadata,
sqlStringGenerationContext

View File

@ -0,0 +1,124 @@
package org.hibernate.test.inheritance;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
@RequiresDialect(PostgreSQL81Dialect.class)
@TestForIssue( jiraKey = "HHH-15115")
public class JoinedInheritanceDeletionTest extends BaseCoreFunctionalTestCase {
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.DEFAULT_SCHEMA, "public" );
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Person.class,
Employee.class,
Customer.class
};
}
@Before
public void setUp() {
inTransaction(
session -> {
Person person = new Person( 1, "Bob" );
Employee employee = new Employee( 2, "Chris", "Software Engineer" );
Customer customer = new Customer( 3, "Miriam", "" );
session.save( person );
session.save( employee );
session.save( customer );
}
);
}
@Test
public void testDelete() {
inTransaction(
session -> {
session.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Entity(name = "Person")
@Inheritance(strategy = InheritanceType.JOINED)
public static class Person {
@Id
private Integer id;
private String name;
public Person() {
}
public Person(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
}
@Entity(name = "Customer")
public static class Customer extends Person {
private String comments;
public Customer() {
}
public Customer(Integer id, String name, String comments) {
super( id, name );
this.comments = comments;
}
public String getComments() {
return comments;
}
}
@Entity(name = "Employee")
public static class Employee extends Person {
private String title;
public Employee() {
}
public Employee(Integer id, String name, String title) {
super( id, name );
this.title = title;
}
public String getTitle() {
return title;
}
}
}