Skip to content

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed #23

@abid-khan

Description

@abid-khan

This exception is thrown when audited entry contains @manytoone relationship.

Assume below entity

@Audited
@Entity
@Table(name = "user")
public class User  {

         ....

    @Audited
    @NotFound(action = NotFoundAction.IGNORE)
    @ManyToOne
    protected User lastModifiedBy;

        ...
        ...

}

For above entity, revision entry has value of ID for lastModifiedBy. And if I try to access lastModifiedBy, below exception is thrown.

Revisions<Integer, User> revisions = userRepository.findRevisions(user
                .getId());
for (Revision<Integer, User> revision : revisions.getContent()) {
       User revisonEntity = revision.getEntity();
       revisonEntity.getLastModifiedBy().getId()
}
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:168)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions