-->
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.  [ 3 posts ] 
Author Message
 Post subject: failed to lazily initialize a collection
PostPosted: Mon Apr 04, 2005 7:45 pm 
Beginner
Beginner

Joined: Sun May 02, 2004 8:04 am
Posts: 36
Hi,

I'm updating my code (a web application) to use Hibernate 3. At some point when my app starts up, I get this stack trace:

Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection (org.gridlab.gridsphere.services.core.portal.PortalConfigSettings.attributes) - no session or session was closed
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:179)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
        at org.hibernate.collection.PersistentMap.get(PersistentMap.java:122)
        at org.gridlab.gridsphere.services.core.portal.PortalConfigSettings.getAttribute(PortalConfigSettings.java:77)


The class PortalConfigSettings looks like the following and the code fails in the getAttributes method shown:

Code:
public class PortalConfigSettings {
    private String oid = null;
    private boolean canCreateAccount = false;
    private Set defaultGroups = null;
    private String defaultTheme = null;
    private Map attributes = new HashMap();
   ...
    // setter and getters

  // code fails in here!!
   public String getAttribute(String name) {
        return (String) attributes.get(name);
    }


}

My mapping file looks like:

Code:
<hibernate-mapping>
    <class        name="org.gridlab.gridsphere.services.core.portal.PortalConfigSettings
"
        table="portalconfigsettings">

        <id
            name="oid"
            column="gsoid"
            type="java.lang.String"
            length="32"
            >
            <generator class="uuid.hex"/>

        </id>
        <property name="CanUserCreateAccount" type="boolean" column="canusercreateacct"/>
        <property name="DefaultTheme" type="string" column="defaulttheme"/>
        <set name="DefaultGroups" cascade="all">
            <key column="defaultgroup_oid"/>
            <one-to-many class="org.gridlab.gridsphere.portlet.impl.SportletGr
oup"/>
        </set>
        <map name="attributes" table="portalconfigattributes">
            <key column="gsoid"/>
            <index column="attribute" type="string"/>
            <element column="value" type="string"/>
        </map>
    </class>
</hibernate-mapping>



Any idea why this worked in 2.1, or what I need to do to make it work in Hibernate 3?

Thanks very much, Jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 5:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
read the migration guide

lazy default behaviour has change, in your case just add fetch="join" in the mapping file, but read the migration guide

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 3:09 pm 
Beginner
Beginner

Joined: Sun May 02, 2004 8:04 am
Posts: 36
I tried adding fetch="join" like so:

<map name="attributes" table="portalconfigattributes" fetch="join">
<key column="gsoid"/>
<map-key column="attribute" type="string"/>
<element column="value" type="string"/>
</map>

but that doesn't seem to work. At start up I create my object for the first time:

Code:
PortalConfigSettings configSettings = new PortalConfigSettings();
configSettings.setDefaultGroups(defaultGroups);

try {
session = factory.openSession();
            tx = null;
            tx = session.beginTransaction();

} catch (HibernateException e) {
            if (tx != null) {
                tx.rollback();
            }
            log.error("Could not complete transaction", e);
            e.printStackTrace();
            throw e;
        } finally {
            session.close();
        }


and I get this stacktrace:

Code:
76358 [http-8080-Processor25] (AbstractFlushingEventListener.java:277) ERROR org.hibernate.event.def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
        at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
        at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:880)
        at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:23)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.