org.hibernate.LazyInitializationException: could not initialize proxy - no Session

Hibernate JIRA | Marc Schipperheyn | 4 years ago
  1. 0

    This has been bugging me for a few versions now. I often get LazyExceptions in Classbridges. {code} org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:272) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) at nl.msw.compraventa.model.user.Usor_$$_javassist_78.getRoles(Usor_$$_javassist_78.java) at nl.msw.compraventa.dao.hibernate.bridge.OfferClassBridge.set(OfferClassBridge.java:94) {code} This particular entity is mapped like so {code} @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorValue(value = "OFF") @DiscriminatorColumn(name = "DTYPE", discriminatorType= DiscriminatorType.STRING, length = 3) @Indexed(interceptor=OfferIndexingInterceptor.class) @ClassBridge(impl=OfferClassBridge.class,index=org.hibernate.search.annotations.Index.YES,analyze=Analyze.NO,store=Store.NO) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.OFFER) public class Offer{ @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "FK_UserID", nullable = false, updatable = true) @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region=CacheRegion.USER) @IndexedEmbedded(includePaths={"id"}) @JsonView(Views.Detail.class) public User getVendor() { return vendor; } @Entity(name = "User2") @Indexed @NaturalIdCache @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) public class User{ @ManyToMany(cascade=CascadeType.MERGE,fetch = FetchType.LAZY) @JoinTable(name = "User_UserRoles", joinColumns = @JoinColumn(nullable = false), inverseJoinColumns = @JoinColumn(nullable = false)) @Fetch(FetchMode.SELECT) @BatchSize(size=10) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) @IndexedEmbedded(prefix="role.") @JsonIgnore public Set<UserRole> getRoles() { return roles; } {code}

    Hibernate JIRA | 4 years ago | Marc Schipperheyn
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  2. 0

    This has been bugging me for a few versions now. I often get LazyExceptions in Classbridges. {code} org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:272) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) at nl.msw.compraventa.model.user.Usor_$$_javassist_78.getRoles(Usor_$$_javassist_78.java) at nl.msw.compraventa.dao.hibernate.bridge.OfferClassBridge.set(OfferClassBridge.java:94) {code} This particular entity is mapped like so {code} @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorValue(value = "OFF") @DiscriminatorColumn(name = "DTYPE", discriminatorType= DiscriminatorType.STRING, length = 3) @Indexed(interceptor=OfferIndexingInterceptor.class) @ClassBridge(impl=OfferClassBridge.class,index=org.hibernate.search.annotations.Index.YES,analyze=Analyze.NO,store=Store.NO) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.OFFER) public class Offer{ @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "FK_UserID", nullable = false, updatable = true) @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region=CacheRegion.USER) @IndexedEmbedded(includePaths={"id"}) @JsonView(Views.Detail.class) public User getVendor() { return vendor; } @Entity(name = "User2") @Indexed @NaturalIdCache @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) public class User{ @ManyToMany(cascade=CascadeType.MERGE,fetch = FetchType.LAZY) @JoinTable(name = "User_UserRoles", joinColumns = @JoinColumn(nullable = false), inverseJoinColumns = @JoinColumn(nullable = false)) @Fetch(FetchMode.SELECT) @BatchSize(size=10) @Cache(usage=CacheConcurrencyStrategy.READ_WRITE,region=CacheRegion.USER) @IndexedEmbedded(prefix="role.") @JsonIgnore public Set<UserRole> getRoles() { return roles; } {code}

    Hibernate JIRA | 4 years ago | Marc Schipperheyn
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  3. 0

    Struts 2 Json Result Hibernate LazyInitialization - How to deserialize within a hibernate session

    Stack Overflow | 4 years ago | surfealokesea
    org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    @Transactional(readOnly = true) leads to LazyInitializationException

    Stack Overflow | 4 years ago | beginner_
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  6. 0

    ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Session

    Stack Overflow | 3 years ago | user2879071
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session

  1. MoYapro 2 times, last 4 weeks ago
14 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hibernate.LazyInitializationException

    could not initialize proxy - no Session

    at org.hibernate.proxy.AbstractLazyInitializer.initialize()
  2. Hibernate
    JavassistLazyInitializer.invoke
    1. org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165)
    2. org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:272)
    3. org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
    3 frames
  3. nl.msw.compraventa
    OfferClassBridge.set
    1. nl.msw.compraventa.model.user.Usor_$$_javassist_78.getRoles(Usor_$$_javassist_78.java)
    2. nl.msw.compraventa.dao.hibernate.bridge.OfferClassBridge.set(OfferClassBridge.java:94)
    2 frames