-->
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.  [ 2 posts ] 
Author Message
 Post subject: loading collections; values are not correct
PostPosted: Wed Nov 14, 2007 10:20 am 
Newbie

Joined: Tue Oct 09, 2007 12:07 pm
Posts: 6
Hibernate version: 3.2

Hello,

I have realized some strange behavior on loading collection-properties.

(After reading the book "Java Persist with Hibernate", searching in the documentation and in the Internet I am still without any answer)

Let's consider an entity which property is a collection.
This is configured as the following:

Code:
<class dynamic-insert="false" dynamic-update="false"
        entity-name="defaultexample " select-before-update="false">
        <id column="XHDOC" name=" XHDOC" type="string">
            <generator class="native"/>
        </id>
<bag name="DOCTYPES" fetch="subselect" table=" DEFAULTEXAMPLEDOCTYPES">
            <key column="HDOC "/>
            <one-to-many entity-name="defaultexampleDOCTYPES"/>
        <loader query-ref="sysdoctypes"/>
</bag>

…..</class>


The respective entity is defined as a class:

Code:
<class dynamic-insert="false" dynamic-update="false"
        entity-name="defaultexampleDOCTYPES" select-before-update="false">
        <id column="HDOC" name="HDOC" type="string">
            <generator class="native"/>
        </id>     
        <property column="MULTIVAL" name="MULTIVAL " type="string"/>
</class>


As you have seen, I am using the sql query to load the belonging collections:

Code:
<sql-query name="sysdoctypes">
                <load-collection alias="d" role=" defaultexample.DOCTYPES"/>
               select {d.*}
            from DEFAULTEXAMPLEDOCTYPES d
            where d.HDOC=?
</sql-query>


After the issuing the following query


Code:
String stmt = "from defaultexample d where d.XHDOC = :id ";
List result = session.createQuery(stmt2).setParameter("id",
                "7B17AFBF645441420F0001000000F80B000000000000").list();


The result of the query is a list of maps:

Code:
[{...$type$=defaultexample, ..., XHDOC=7B17AFBF645441420F0001000000F80B000000000000, ….
SYSDOCTYPES=
[{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES},
{MULTIVAL=TIF, HDOC=7B17AFBF645441420F0001000000F80B000000000000, $type$=defaultexampleSYSDOCTYPES}], …]


The strangest thing here is that the count of the returned multivalues is correct (it must be 6 values) but every value is set at TIF, however it must be:
Code:
[TIF
gif
htm
pdf
doc
jpg]

That means, each value of the returned by Hibernate List is set to the first value of the correct result. Do I miss something in configuration? What would be the correct way to return such collections.

Thank you very much in advance for your help!
Larysa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 14, 2007 12:55 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
The problem is with the defaultexample mapping. You define a bag but set the key column to be the primary key of the defaultexampleDOCTYPES table:
Code:
<bag name="DOCTYPES" fetch="subselect" table="DEFAULTEXAMPLEDOCTYPES">
            <key column="HDOC "/>
...

The key column should be a column in the child table that holds the primary key of the _parent_ table. You've defined it as a column in the child table holding the primary key of the _child_ table.


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