HHH-12291 - PersistentBag throws NullPointerException when deleting an entity via Cascade
Rename test case and spot the problem
This commit is contained in:
parent
a42d176ccd
commit
c12a4423a7
|
@ -28,19 +28,19 @@ import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTestCase {
|
public class MultiLevelCascadeCollectionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger( MultiLevelCascadeToStringTest.class );
|
private static final Logger log = Logger.getLogger( MultiLevelCascadeCollectionTest.class );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -62,7 +62,7 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-12291" )
|
@TestForIssue( jiraKey = "HHH-12291" )
|
||||||
public void testHibernateDeleteEntityWithoutCallingToString() throws Exception {
|
public void testHibernateDeleteEntityWithoutCallingToString() throws Exception {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
|
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
|
||||||
|
@ -78,7 +78,7 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-12294" )
|
@TestForIssue( jiraKey = "HHH-12294" )
|
||||||
public void testHibernateDeleteEntityCallingToString() throws Exception {
|
public void testHibernateDeleteEntityInitializeCollections() throws Exception {
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
|
MainEntity mainEntity = entityManager.find(MainEntity.class, 99427L);
|
||||||
|
|
||||||
|
@ -88,8 +88,10 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
|
Optional<SubEntity> subEntityToRemove = mainEntity.getSubEntities().stream()
|
||||||
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
|
.filter(subEntity -> "123A".equals(subEntity.getIndNum())).findFirst();
|
||||||
if ( subEntityToRemove.isPresent() ) {
|
if ( subEntityToRemove.isPresent() ) {
|
||||||
log.infof("Entity to be removed: %s", subEntityToRemove.get());
|
SubEntity subEntity = subEntityToRemove.get();
|
||||||
mainEntity.removeSubEntity(subEntityToRemove.get());
|
assertEquals( 1, subEntity.getSubSubEntities().size() );
|
||||||
|
assertEquals( 0, subEntity.getAnotherSubSubEntities().size() );
|
||||||
|
mainEntity.removeSubEntity( subEntity );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -238,17 +240,6 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
|
|
||||||
return Objects.hash(super.hashCode(), subIdNum);
|
return Objects.hash(super.hashCode(), subIdNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SubEntity{" +
|
|
||||||
"subIdNum=" + subIdNum +
|
|
||||||
", indNum='" + indNum + '\'' +
|
|
||||||
", familyIdentifier='" + familyIdentifier + '\'' +
|
|
||||||
", subSubEntities=" + subSubEntities +
|
|
||||||
", anotherSubSubEntities=" + anotherSubSubEntities +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -273,7 +264,6 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
@JoinColumn(name = "ID_NUM", referencedColumnName = "ID_NUM", insertable = false, updatable = false),
|
@JoinColumn(name = "ID_NUM", referencedColumnName = "ID_NUM", insertable = false, updatable = false),
|
||||||
@JoinColumn(name = "PERSON", referencedColumnName = "FAMILY_IDENTIFIER", insertable = false, updatable = false)
|
@JoinColumn(name = "PERSON", referencedColumnName = "FAMILY_IDENTIFIER", insertable = false, updatable = false)
|
||||||
})
|
})
|
||||||
@Id
|
|
||||||
private SubEntity subEntity;
|
private SubEntity subEntity;
|
||||||
|
|
||||||
public Long getIdNum() {
|
public Long getIdNum() {
|
||||||
|
@ -406,7 +396,6 @@ public class MultiLevelCascadeToStringTest extends BaseEntityManagerFunctionalTe
|
||||||
@JoinColumn(name = "ID_NUM", referencedColumnName = "ID_NUM"),
|
@JoinColumn(name = "ID_NUM", referencedColumnName = "ID_NUM"),
|
||||||
@JoinColumn(name = "IND_NUM", referencedColumnName = "IND_NUM")
|
@JoinColumn(name = "IND_NUM", referencedColumnName = "IND_NUM")
|
||||||
})
|
})
|
||||||
@Id
|
|
||||||
private SubEntity subEntity;
|
private SubEntity subEntity;
|
||||||
|
|
||||||
public Long getIdNum() {
|
public Long getIdNum() {
|
Loading…
Reference in New Issue