Announcement Announcement Module
Collapse
No announcement yet.
Hibernate: Unable to get a collection but can get the size Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate: Unable to get a collection but can get the size

    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&#40;CATEGORY_ID&#41;;
    category.getItems&#40;&#41;.size&#40;&#41; // this works -- output the correct number of items
    category.getItems&#40;&#41; // 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

  • #2
    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

    Comment


    • #3
      I also get this error in my Tomcat log file:

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

      Comment


      • #4
        I found a solution... please ignore this thread.

        Thanks

        Comment


        • #5
          Can you tell us what caused theStackOverflowError ?

          Somehow hibernate went in an endless recursive loop ?

          Comment


          • #6
            I changed my toString(), hashCode(), compareTo() and equals() functions not to include the primary keys and collections.

            HTH

            Comment

            Working...
            X