HHH-13110 - @PreUpdate method on a Embeddable null on the parent caused NullPointerException
This commit is contained in:
parent
849e2a5a53
commit
3ff3615d00
|
@ -32,7 +32,9 @@ final class EmbeddableCallback extends AbstractCallback {
|
|||
public boolean performCallback(Object entity) {
|
||||
try {
|
||||
Object embeddable = embeddableGetter.get( entity );
|
||||
callbackMethod.invoke( embeddable );
|
||||
if ( embeddable != null ) {
|
||||
callbackMethod.invoke( embeddable );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
|
|
|
@ -18,11 +18,11 @@ import org.junit.Test;
|
|||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12326")
|
||||
public class EmbeddableCallbackTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
|
@ -31,9 +31,11 @@ public class EmbeddableCallbackTest extends BaseEntityManagerFunctionalTestCase
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12326")
|
||||
public void test() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Employee employee = new Employee();
|
||||
employee.details = new EmployeeDetails();
|
||||
employee.id = 1;
|
||||
|
||||
entityManager.persist( employee );
|
||||
|
@ -47,6 +49,24 @@ public class EmbeddableCallbackTest extends BaseEntityManagerFunctionalTestCase
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13110")
|
||||
public void testNullEmbeddable() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Employee employee = new Employee();
|
||||
employee.id = 1;
|
||||
|
||||
entityManager.persist( employee );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Employee employee = entityManager.find( Employee.class, 1 );
|
||||
|
||||
assertEquals( "Vlad", employee.name );
|
||||
assertNull( employee.details );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Employee")
|
||||
public static class Employee {
|
||||
|
||||
|
@ -55,7 +75,7 @@ public class EmbeddableCallbackTest extends BaseEntityManagerFunctionalTestCase
|
|||
|
||||
private String name;
|
||||
|
||||
private EmployeeDetails details = new EmployeeDetails();
|
||||
private EmployeeDetails details;
|
||||
|
||||
@PrePersist
|
||||
public void setUp() {
|
||||
|
|
Loading…
Reference in New Issue