-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problems initializing collection!?
PostPosted: Sat Dec 20, 2003 6:44 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
I'm using Hibernate 2.1.1.
I'm using "fetch" in the query to initialize the collection!
I don't understand why is he giving me the following error:
Code:
ERROR: Failed to lazily initialize a collection - no Session
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:213)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:69)
   at net.sf.hibernate.collection.Set.toString(Set.java:219)
( ... )


-----------------------------------------------------
Mapping file (generated with Middlegen R3)
-----------------------------------------------------

Mistura

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="vo.Mistura"
    table="mistura"
>

    <id
        name="id"
        type="long"
        column="id"
    >
        <generator class="increment" />
    </id>
   
    <property
        name="userId"
        type="java.lang.String"
        column="user_id"
        not-null="true"
        length="10"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to MisturaStock -->
    <set
        name="misturaStocks"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="mistura_fk" />
        </key>
        <one-to-many
            class="vo.MisturaStock"
        />
    </set>

</class>
</hibernate-mapping>


-----------------
Testing code
-----------------

Code:
SessionFactory sessionFactory = HibernateFactory.createFactory();
session = sessionFactory.openSession();

res = session.find("from vo.Mistura as m " +
         "left join fetch misturaStocks " +
         "where m.userId= '" + user + "'");

   
session.close();


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 20, 2003 6:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
it should be "left join fetch m.misturaSocks" i think


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 20, 2003 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
"left join fetch m.misturaStocks" I mean - i want that edit function :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 20, 2003 6:58 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
gloeglm wrote:
"left join fetch m.misturaStocks" I mean - i want that edit function :)


Thanks very much.
It worked.


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