Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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