Skip to content

Commit

Permalink
HHH-13110 - @PreUpdate method on a Embeddable null on the parent caus…
Browse files Browse the repository at this point in the history
…ed NullPointerException
  • Loading branch information
vladmihalcea authored and gsmet committed Dec 5, 2018
1 parent 849e2a5 commit 3ff3615
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Expand Up @@ -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) {
Expand Down
Expand Up @@ -18,11 +18,11 @@

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
Expand All @@ -31,9 +31,11 @@ protected Class<?>[] getAnnotatedClasses() {
}

@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 );
Expand All @@ -47,6 +49,24 @@ public void test() {
} );
}

@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 {

Expand All @@ -55,7 +75,7 @@ public static class Employee {

private String name;

private EmployeeDetails details = new EmployeeDetails();
private EmployeeDetails details;

@PrePersist
public void setUp() {
Expand Down

0 comments on commit 3ff3615

Please sign in to comment.