Given
- A polymorphic single table entity using column discriminator
- One persisted instance of this entity
- Another persisted instance using another subclass/discriminator
- A simple Filter is defined
When
- Activating the filter and executing a deletion for all entities from a single discriminator
Then
- All entities, regardless their discriminator, are deleted
@Entity
@Table(name = "ENTITY_A")
@DiscriminatorColumn(name = "DISC_COL", discriminatorType = DiscriminatorType.INTEGER)
@FilterDef(name = "DUMMY_FILTER", defaultCondition = "(ID IS NOT NULL)")
@Filter(name = "DUMMY_FILTER")
public abstract class AbstractEntityA {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
Integer id;
}
@Entity
@DiscriminatorValue("1")
public class EntityAChildOne extends AbstractEntityA {}
@Entity
@DiscriminatorValue("2")
public class EntityAChildTwo extends AbstractEntityA {}
@Test
public void hhhXXXXTest() throws Exception {
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
EntityAChildOne entityAChildOne = new EntityAChildOne();
EntityAChildTwo entityAChildTwo = new EntityAChildTwo();
s.persist(entityAChildOne);
s.persist(entityAChildTwo);
tx.commit();
}
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
s.enableFilter("DUMMY_FILTER");
MutationQuery deleteQuery = s.createMutationQuery("delete from org.hibernate.bugs.EntityAChildTwo");
int actual = deleteQuery.executeUpdate();
assertThat(actual).isEqualTo(1);
tx.commit();
Query<AbstractEntityA> query = s.createQuery("select c from org.hibernate.bugs.AbstractEntityA c",
AbstractEntityA.class);
List<AbstractEntityA> actualList = query.list();
assertThat(actualList).hasSize(1);
}
}
Not enabling the filter will work as expected, only deleting EntityAChildTwo Enabling the filter will ignore completely the discriminator and delete everything in that table. A failing test case is to be attached. |