Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODI5YzE3Y2My...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16435?atlOrigin=eyJpIjoiODI5Yz...
) HHH-16435 (
https://hibernate.atlassian.net/browse/HHH-16435?atlOrigin=eyJpIjoiODI5Yz...
) Discriminators are completely ignored when Filter is active (
https://hibernate.atlassian.net/browse/HHH-16435?atlOrigin=eyJpIjoiODI5Yz...
)
Change By: Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
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
{code:java}@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;
}{code}
{code:java}@Entity
@DiscriminatorValue("1")
public class EntityAChildOne extends AbstractEntityA {}{code}
{code:java}@Entity
@DiscriminatorValue("2")
public class EntityAChildTwo extends AbstractEntityA {}{code}
{code:java} @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);
}
}{code}
{noformat}Hibernate:
delete
from
ENTITY_A
where
(
ID IS NOT NULL
){noformat}
{noformat}org.opentest4j.AssertionFailedError:
Expecting:
<2>
to be equal to:
<1>
but was not.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at org.hibernate.bugs.ORMUnitTestCase.hhhXXXXTest(ORMUnitTestCase.java:79)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at
org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:833){noformat}
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 and also available here [
https://github.
com/ratoaq2/HHH-16435|https://github.com/ratoaq2/HHH-16435|smart-link]
(
https://hibernate.atlassian.net/browse/HHH-16435#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16435#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:89dc9bf )