Andrea Boriero (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-16936 (
https://hibernate.atlassian.net/browse/HHH-16936?atlOrigin=eyJpIjoiNzRhZG...
)
Re: Entity not being removed from persistence context after a delete in JPQL (
https://hibernate.atlassian.net/browse/HHH-16936?atlOrigin=eyJpIjoiNzRhZG...
)
Hi Jean-Baptiste Hainaut (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
) ,
I tried to to create a reproducer for the issue but without any success.
@Jpa(
annotatedClasses = {
EntityDeleteTest.SchoolSetting.class
}
)
public class EntityDeleteTest {
static String SCHOOL_ID = "MY_SCHOOL";
static String SCHOOL_KEY = "ABSENCE_FOR_DAY_OFF";
@Test
public void testIt(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
SchoolSetting schoolSetting = new SchoolSetting( SCHOOL_ID, SCHOOL_KEY, true );
entityManager.persist( schoolSetting );
}
);
scope.inTransaction(
entityManager -> {
SchoolSettingId primaryKey = new SchoolSettingId( SCHOOL_ID, SCHOOL_KEY );
SchoolSetting schoolSetting = entityManager.find(
SchoolSetting.class,
primaryKey
);
entityManager.remove( schoolSetting );
schoolSetting = entityManager.find(
SchoolSetting.class,
primaryKey
);
assertNull( schoolSetting );
}
);
}
@Test
public void testIt2(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
SchoolSetting schoolSetting = new SchoolSetting( SCHOOL_ID, SCHOOL_KEY, true );
entityManager.persist( schoolSetting );
}
);
scope.inTransaction(
entityManager -> {
Query query = entityManager.createQuery( "delete from SchoolSetting s WHERE
s.id.key = :id" );
query.setParameter( "id", SCHOOL_KEY );
query.executeUpdate();
SchoolSetting schoolSetting = entityManager.find(
SchoolSetting.class,
new SchoolSettingId(
SCHOOL_ID,
SCHOOL_KEY
)
);
assertNull( schoolSetting );
}
);
}
@Entity(name = "SchoolSetting")
public static class SchoolSetting {
@EmbeddedId
private SchoolSettingId id;
private boolean activated;
public SchoolSetting() {
}
public SchoolSetting(
final String schoolId,
final String key,
final boolean activated) {
this.id = new SchoolSettingId( schoolId, key );
this.activated = activated;
}
public String getKey() {
return this.id.getKey();
}
}
@Embeddable
public static class SchoolSettingId implements Serializable {
private String schoolId;
@Column(name = "school_key")
private String key;
public SchoolSettingId() {
}
public SchoolSettingId(
final String schoolId,
final String key) {
this.schoolId = schoolId;
this.key = key;
}
public String getSchoolId() {
return schoolId;
}
public String getKey() {
return key;
}
}
}
Can you please provide a complete reproducer?
Thanks
(
https://hibernate.atlassian.net/browse/HHH-16936#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16936#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#100233- sha1:f5b6255 )