HHH-12484 - Improved error output for LazyInitializationException to include entity-related info

Use predefinied entity identifiers
This commit is contained in:
Vlad Mihalcea 2018-04-16 17:50:45 +03:00
parent d8d5bf99da
commit 6c0c44f7d0
1 changed files with 12 additions and 24 deletions

View File

@ -38,24 +38,27 @@ public class LazyLoadingLoggingTest
}; };
} }
@Test @Override
@TestForIssue(jiraKey = "HHH-12484") protected void afterSessionFactoryBuilt() {
public void testNoSession() { doInHibernate( this::sessionFactory, session -> {
Long addressId = doInHibernate( this::sessionFactory, session -> {
Address address = new Address(); Address address = new Address();
address.setId( 1L );
address.setStreet( "Marea albastra" ); address.setStreet( "Marea albastra" );
session.persist( address ); session.persist( address );
Client client = new Client(); Client client = new Client();
client.setId( 1L );
client.setName( "Dorian" ); client.setName( "Dorian" );
client.setAddress( address ); client.setAddress( address );
session.persist( client ); session.persist( client );
return address.getId();
} ); } );
}
@Test
@TestForIssue(jiraKey = "HHH-12484")
public void testNoSession() {
Address address = doInHibernate( this::sessionFactory, s -> { Address address = doInHibernate( this::sessionFactory, s -> {
return s.load( Address.class, addressId ); return s.load( Address.class, 1L );
} ); } );
try { try {
@ -75,21 +78,8 @@ public class LazyLoadingLoggingTest
@Test @Test
@TestForIssue(jiraKey = "HHH-12484") @TestForIssue(jiraKey = "HHH-12484")
public void testDisconnect() { public void testDisconnect() {
Long addressId = doInHibernate( this::sessionFactory, s -> {
Address address = new Address();
address.setStreet( "Marea albastra" );
s.persist( address );
Client client = new Client();
client.setName( "Dorian" );
client.setAddress( address );
s.persist( client );
return address.getId();
} );
doInHibernate( this::sessionFactory, session -> { doInHibernate( this::sessionFactory, session -> {
Address address = session.load( Address.class, addressId ); Address address = session.load( Address.class, 1L );
AbstractSharedSessionContract sessionContract = (AbstractSharedSessionContract) session; AbstractSharedSessionContract sessionContract = (AbstractSharedSessionContract) session;
sessionContract.getJdbcCoordinator().close(); sessionContract.getJdbcCoordinator().close();
@ -116,7 +106,6 @@ public class LazyLoadingLoggingTest
@Entity(name = "Address") @Entity(name = "Address")
public static class Address { public static class Address {
@Id @Id
@GeneratedValue
private Long id; private Long id;
@Column @Column
@ -154,7 +143,6 @@ public class LazyLoadingLoggingTest
@Entity(name = "Client") @Entity(name = "Client")
public static class Client { public static class Client {
@Id @Id
@GeneratedValue
private Long id; private Long id;
@Column @Column