-->
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.  [ 1 post ] 
Author Message
 Post subject: Empty collection being returned. Not sure why though ...
PostPosted: Fri Apr 30, 2004 8:00 am 
Newbie

Joined: Fri Apr 30, 2004 7:12 am
Posts: 4
Hi there ... :-)

I wonder if someone can help me.

I'm trying to retrieve a collection from an object, but I'm getting nothing back. Haven't a clue why this is, because it is stored correctly on the database. I've set up the following mappings:

[code]<hibernate-mapping>

<class name="ScratchPad" table="scratchPad">

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

<bag name="pageCalendars" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="id"/>
<one-to-many class="PageCalendar"/>
</bag>

<many-to-one name="school"
class="School"
column="schoolId"
not-null="true"/>

</class>
</hibernate-mapping>[/code]

-----------------------------------------------
[code]
<hibernate-mapping>

<class name="Content" table="content">

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


<bag name="pageCalendars" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="id"/>
<one-to-many class="PageCalendar"/>
</bag>

<many-to-one name="contentType"
class="com.starstream.school.resources.schemas.database.ContentType"
column="contentTypeId"
not-null="true"/>

</class>

</hibernate-mapping>[/code]

----------------------------------------------

[code]
<hibernate-mapping>

<class name="PageCalendar" table="pageCalendar">

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

<property name="showFrom" column="showFrom" type="date" not-null="false"/>
<property name="showTo" column="showTo" type="date" not-null="false"/>
<property name="active" column="active" type="boolean" not-null="true"/>

<many-to-one name="content" cascade="delete"
class="com.starstream.school.resources.schemas.database.Content"
column="contentId"
not-null="true"/>

<many-to-one name="scratchPad" cascade="delete"
class="com.starstream.school.resources.schemas.database.ScratchPad"
column="scratchPadId"
not-null="true"/>

</class>

</hibernate-mapping>[/code]


I have created a record on the PageCalendar table using the following code:

----------------------------------------------------------------------------------------------
[code]
pageCalendar.setContent(content);
content.getPageCalendars().add(pageCalendar);
pageCalendar.setScratchPad(scratchPad);
scratchPad.getPageCalendars().add(pageCalendar);
try {
logger.debug("Saving page calendar record");
session.flush();
return pageCalendar;
}
[/code]
----------------------------------------------------------------------------------------------

This bit works, because I've had a look at the table, and the
new record has been written, and also has the correct fields filled in
for contentId and ScratchPadId.


But when I do this:
----------------------------------------------------------------------------------------
[code] ScratchPad scratchPad = new ScratchPad();
session.load(scratchPad, new Long(2));

logger.debug("Title ==> " + scratchPad.getName());
logger.debug("Number of calendars ==> " + scratchPad.getPageCalendars().size());[/code]
----------------------------------------------------------------------------------------

The collection inside scratchPad is empty. Even though the correct values are still OK on the database.

I'm obviously missing something here. Can someone help me out with this?

Thanks


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

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.