-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: LazyInitializationException despite lazy=false mapping
PostPosted: Thu Jan 17, 2008 5:44 pm 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
We have just converted a POJO used in a Many-to-one relationship from xDoclet-based mappings to Annotations (this is the first item of many we will convert) and get a LazyInitializationException accessing the POJO.

This is not a collection of pojos, so we are surprised it is lazily loaded at all. Also, the parent class (test.Item) has the property default-lazy="false" set on the whole class. This lazy=false setting seems to work for other one-to-many relationships that have not been converted to annotations.

Is there some lazy setting on the sub-item (test.RelatedItem) itself that is overriding the settings of the parent class?

The sub-item itself can be explicitly saved and loaded without any problem, but when saved as a related item in a one-to-many we get this error.

Hibernate version:
3.2.5
annotations 3.2.0

Mapping documents:

We have one mapping document that is a hbm.xml file and another that is specified via annotations. We are starting the process of incrementally moving to annotations.

Item.hbm.xml (edited for brevity):
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false"
>
    <class
        name="test.Item"
        table="items"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >

        <id
            name="guid"
            column="item_guid"
            type="java.lang.String"
        >
            <generator class="assigned">
             
            </generator>
        </id>

        <many-to-one
            name="relatedItem"
            class="test.RelatedItem"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="relateditem_guid"
            />
        </many-to-one>
    </class>

</hibernate-mapping>


New annotated class (edited for brevity):
Code:
package test;

import javax.persistence.*;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;


@Entity
@Table(name="relateditem")
public class RelatedItem extends Persistent
        implements Serializable {

    private String guid;
    private String description;

    public RelatedItem() {    }

    @Id
    @Column(name="RelatedItem_GUID")
    public String getGuid() {
        return this.guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    @Basic @Column(length=50, name="description")
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}


hibernate.cfg.xml section:
Code:
   <session-factory>
      <mapping resource="test/item.hbm.xml"/>   
      <mapping class="test.Place"/>
   </session-factory>


Full stack trace of any exception that occurs:
Code:
ERROR 2008-01-17 16:31:18,425 [exception.ExInternalException] line:32 - Internal Exception:: Error opening ItemReport(0a0a-2283-11788172aa1-b6220b9f-0-fd51)
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
   at test.RelatedItem$$EnhancerByCGLIB$$28d6ed11.getDescription(<generated>)
   at test.RelatedItemButton.updateDisplay(RIButton.java:138)
   ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:22 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Looks like your application lacks a session in the context where that code is being executed. It is not a lazy initializayion problem.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.