-->
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.  [ 7 posts ] 
Author Message
 Post subject: Unable to retrieve a collection but can get the size
PostPosted: Thu Dec 30, 2004 1:23 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
Hibernate version: 2.1.7b

Mapping documents:
Code:
<class name="Category">
    <id name="id" column="CATEGORY_ID"/>
    ...
    <bag name="items"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan">
        <key column="CATEGORY_ID"/>
        <one-to-many class="Item"/>
    </bag>
</class>

<class name="Item">
    <id name="id" column="ITEM_ID"/>
    ...
    <many-to-one name="category
            class="Category"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            foreign-key="FK1_CATEGORY_ID"
            column="CATEGORY_ID"
            not-null="true"
    />
</class>

Name and version of the database you are using: PostgreSQL 8.0RC2

I am using Hibernate, Spring and Struts. In my Action class I use the following code to get a list of items belong to a category:

Code:
Category category = categoryManager.getCategory(CATEGORY_ID);
category.getItems().size() // this works -- output the correct number of items
category.getItems() // It stops, doens't output anything... no exception.


I use the above code in my JUnit tests and it passed all the tests.

Any idea on what I am doing wrong? Have been trying to find a solution for days to this problem.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 1:44 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
In my Junit test, Hibernate generates one query to get the list size and the list itself.

In my Action class, Hibernate generates two queries: one is to get the list size and this query is the same as the query in the test. The second query looks very strange.

Why is it gernating two queries in my Action class but generate only one in the test?

My Spring configuration? But it works in the test.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 7:18 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
I also get this in my Tomcat log file:

Quote:
2004-12-30 22:07:17 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.StackOverflowError


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 9:43 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
I found a solution... please ignore this thread.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 1:35 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Two tips for:

1. Please post your solution, even if it does not relate to hibernate. Others read your thread and then it would be helpful to see the solving.

2. Don't advertise in such a forum in mass way, even it is for firefox.

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 6:25 pm 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
1. I changed my toString(), hashCode(), compareTo() and equals() functions not to include the primary keys and collections.

2. Sure, just removed it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 8:18 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
newreaders wrote:
I changed my toString(), hashCode(), compareTo() and equals() functions not to include the primary keys and collections.


How on earth did your unit test pass if the toString(), hashCode(), compareTo() and/or equals() methods had some kind of infinite recursion that caused a stack overflow in Tomcat?


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