MK (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZWEzYjBlNjNk...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16193?atlOrigin=eyJpIjoiZWEzYj...
) HHH-16193 (
https://hibernate.atlassian.net/browse/HHH-16193?atlOrigin=eyJpIjoiZWEzYj...
) LazyInitializationException when accessing loaded reference after session is closed
using bytecode enhancement (
https://hibernate.atlassian.net/browse/HHH-16193?atlOrigin=eyJpIjoiZWEzYj...
)
Issue Type: Bug Affects Versions: 6.2.0.CR2 Assignee: Unassigned Attachments:
lazy-bytecode-enhancement-error.zip Components: hibernate-enhance-maven-plugin Created:
17/Feb/2023 06:00 AM Environment: The error occurs with 6.2.0.CR2 but not 6.1.7.Final.
Priority: Major Reporter: MK (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
A LazyInitializationException occurs when accessing a loaded ManyToOne reference after the
session is closed using lazy initialization bytecode enhancement. It only happens in
combination with second-level caching and batch size.
Entities:
@Entity
@NamedQueries({
@NamedQuery(name = "PersonType.selectAll" ,
query = "SELECT a" +
" FROM EntityA a" ),
})
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class EntityA {
@Id
@GeneratedValue
private Long id;
private String name;
@ManyToOne
private EntityB entityB;
}
@Entity
@BatchSize(size = 500)
public class EntityB {
@Id
@GeneratedValue
private Long id;
private String name;
}
Test Code (entities are created beforehand):
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
List<EntityA> aList =
entityManager.createNamedQuery( "PersonType.selectAll" , EntityA.class)
.getResultList();
entityManager.getTransaction().commit();
entityManager.close();
Assert.assertEquals(1, aList.size());
Assert.assertEquals( "B1" , aList.get(0).getEntityB().getName()); //
LazyInitializationException
Reproducer is attached!
(
https://hibernate.atlassian.net/browse/HHH-16193#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16193#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100216- sha1:3fa9804 )