-->
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.  [ 6 posts ] 
Author Message
 Post subject: failing to retrieve a collection
PostPosted: Tue Jul 13, 2004 3:48 pm 
Newbie

Joined: Tue Jul 13, 2004 3:25 pm
Posts: 4
Location: M
i'm new with hibernate (and spring), i am having troubles trying to retrieve
a collection (defined as lazy). Here is the relevant code:

Father.hbm.xml
Code:
    <!-- bi-directional one-to-many association to MapaConceptual -->
    <set
        name="children"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="idFather" />
        </key>
        <one-to-many
            class="Father"
        />
    </set>


Father.java
Code:
    public Set getChildren() {
        return this.children;
    }
    public void setChildren(Set children) {
        this.children = children;
    }


FatherDao.java
Code:
    Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
    try {
        session.lock(father, LockMode.NONE) ;
        java.util.Set set = father.getChildren() ;
        log.info("children.size = " + set.size()) ;

        return new java.util.ArrayList(set) ;

    } catch (HibernateException ex) {
        throw SessionFactoryUtils.convertHibernateAccessException(ex);
    }


a NullPointerException occurs in the println line, the children set is null, and i'm positive there is data associated with the given father.

please help! :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 3:59 pm 
Newbie

Joined: Tue Jul 13, 2004 3:25 pm
Posts: 4
Location: M
i forgot to mention what the log output is:

Code:
14:50:18,906 DEBUG SessionImpl:1670 - reassociating transient instance: [Father#7]
14:50:18,906 DEBUG JDBCTransaction:82 - rollback
14:50:18,906 DEBUG SessionImpl:572 - transaction completion
14:50:18,906 DEBUG JDBCTransaction:103 - re-enabling autocommit
14:50:18,906 DEBUG SessionImpl:560 - closing session
14:50:18,906 DEBUG SessionImpl:3327 - disconnecting session
14:50:18,906 DEBUG SessionImpl:572 - transaction completion
java.lang.NullPointerException
        at FatherDao.getChildren(FatherDao.java:56)


please, note that immedialtly after the "reassociating transient instance" a rollback occurs, what could be going wrong at that point??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 4:08 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Actually, the NullPointer occurs as soon as you call getChildren (according to the stacktrace). What does line 56 of your FatherDAO look like?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 5:40 pm 
Newbie

Joined: Tue Jul 13, 2004 3:25 pm
Posts: 4
Location: M
is the
Code:
log.info("children.size = " + set.size())
part :/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 6:05 pm 
Newbie

Joined: Tue Jul 13, 2004 3:25 pm
Posts: 4
Location: M
i have another collection associated and that is been fetched ok...

some part i din't mentioned is that Child is a subclass of other class, so at database level the idFather column doesn't exist in the Child table...
i'm affraid that is the problem but if so, how do i overcome it ??

the thing is, i want Father to have a collection of Child, not of the superclass of it, this are the table definitions:

Code:
Father              Thing            Child
------              ----------       ---------
id                  id               id        (PK FK that references Thing.id)
name                name             color
                    idFather



this is the mapping for Child in Thing.hbm.xml
Code:
<class name="Thing" table="thing" >

    <id name="id" type="int" unsaved-value="0" >
        <generator class="identity" />
    </id>

    <property name="name"  type="java.lang.String" not-null="true" />

    <!-- bi-directional many-to-one association to Usuario -->
    <many-to-one name="father" class="Father" not-null="true" >
        <column name="idFather" />
    </many-to-one>

    <joined-subclass name="Child" table="child" >
        <key column="id"/>
        <property name="name"  type="java.lang.String" not-null="true" />
    </joined-subclass>

</class>


thanks for your comments


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 7:45 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
gromit wrote:
is the
Code:
log.info("children.size = " + set.size())
part :/


Oops, silly me :(

I'm tired and my brain hurts. What threw me off is that if we lazy load a collection and nothing is found it just returns an empty collection.

However, this

<one-to-many
class="Father"
/>

doesn't look right in the Father.hbm.xml, shouldn't the class be Thing or Child (you decide :))


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