-->
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.  [ 9 posts ] 
Author Message
 Post subject: Find returns several recorcs when there is just one in db :(
PostPosted: Mon Dec 13, 2004 10:53 am 
Newbie

Joined: Sun Apr 04, 2004 6:19 am
Posts: 15
Hibernate version: 2.1.7

Code:
               
list = getHibernateTemplate()
                       .createCriteria(session, Someclass.class)
                       .add(Expression.eq("name", name))
                       .list();



returns 3 copies of the same object.
There is only one record in the table.

Class overrides "equals", compares only id.

Is this considered a "feature" or a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 1:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
not enough info to help you

what about generated sql?

are you sure about unicity?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 7:11 pm 
Newbie

Joined: Sun Apr 04, 2004 6:19 am
Posts: 15
Class has some one-to-* associations.

Removing "outer-join=true" has "fixes" the problem ^^.

So it's a "feature"?!?

What do you mean by "unicity"?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 10:43 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
It is obviously we need more info to prove your issuce.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 5:52 am 
Newbie

Joined: Sun Apr 04, 2004 6:19 am
Posts: 15
I can provide any information you need. Here is generated sql:

Code:
Hibernate: select this.ATTRIBUTE_SET_TYPE_ID as ATTRIBUT1_1_, this.NAME as NAME1_, this.DESCRIPTION as DESCRIPT3_1_, enumeratio1_.ATTRIBUTE_SET_TYPE_ID as ATTRIBUT1___, enumeratio1_.ENUMERATION_ID as ENUMERAT2___, enumeratio2_.ENUMERATION_ID as ENUMERAT1_0_, enumeratio2_.DESCRIPTION as DESCRIPT2_0_, enumeratio2_.NAME as NAME0_ from ATTRIBUTE_SET_TYPE this, MM_ATT_SET_TYPE_ENUM enumeratio1_, ENUMERATION enumeratio2_ where this.NAME=? and this.ATTRIBUTE_SET_TYPE_ID=enumeratio1_.ATTRIBUTE_SET_TYPE_ID(+) and enumeratio1_.ENUMERATION_ID=enumeratio2_.ENUMERATION_ID(+)

Hibernate: select enumeratio0_.ENUMERATION_ID as ENUMERAT4___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1_0_, enumeratio0_.NAME as NAME0_, enumeratio0_.DESCRIPTION as DESCRIPT3_0_, enumeratio0_.ENUMERATION_ID as ENUMERAT4_0_ from ENUMERATION_VALUE enumeratio0_ where enumeratio0_.ENUMERATION_ID=?

Hibernate: select enumeratio0_.ENUMERATION_ID as ENUMERAT4___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1_0_, enumeratio0_.NAME as NAME0_, enumeratio0_.DESCRIPTION as DESCRIPT3_0_, enumeratio0_.ENUMERATION_ID as ENUMERAT4_0_ from ENUMERATION_VALUE enumeratio0_ where enumeratio0_.ENUMERATION_ID=?

Hibernate: select parameteri0_.ATTRIBUTE_SET_TYPE_ID as ATTRIBUT1___, parameteri0_.PARAMETER_NAME as PARAMETE2___, parameteri0_.PARAMETER_TYPE as PARAMETE3___, parameteri1_.PARAMETER_NAME as PARAMETE1_0_, parameteri1_.PARAMETER_TYPE as PARAMETE2_0_ from MM_ATT_SET_TYPE_PARAM_INFO parameteri0_, PARAMETER_INFO parameteri1_ where parameteri0_.ATTRIBUTE_SET_TYPE_ID=? and parameteri0_.PARAMETER_NAME=parameteri1_.PARAMETER_NAME and parameteri0_.PARAMETER_TYPE=parameteri1_.PARAMETER_TYPE

Hibernate: select enumeratio0_.ENUMERATION_ID as ENUMERAT4___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1___, enumeratio0_.ENUMERATION_VALUE_ID as ENUMERAT1_0_, enumeratio0_.NAME as NAME0_, enumeratio0_.DESCRIPTION as DESCRIPT3_0_, enumeratio0_.ENUMERATION_ID as ENUMERAT4_0_ from ENUMERATION_VALUE enumeratio0_ where enumeratio0_.ENUMERATION_ID=?



here is hbm.xml file for Attribute_set_Type class:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
    name="com.biofrontera.discovery.hibernate.AttributeSetType"
    table="ATTRIBUTE_SET_TYPE"
>
    <id
        name="attributeSetTypeId"
        type="java.lang.Long"
        column="ATTRIBUTE_SET_TYPE_ID"
    >
        <generator class="sequence">
            <param name="sequence">SQ_ATTRIBUTE_SET_TYPE</param>
        </generator>
    </id>

    <property
        name="name"
        type="java.lang.String"
        column="NAME"
        not-null="true"
        unique="true"
        length="50"
    >
    </property>
    <property
        name="description"
        type="java.lang.String"
        column="DESCRIPTION"
        not-null="true"
        length="200"
    >
    </property>

    <!-- Associations -->

    <!-- uni-directional many-to-many association to Enumeration -->
    <set
        name="enumerations"
        lazy="false"
        outer-join="true"
      cascade="none"
        table="MM_ATT_SET_TYPE_ENUM"
    >
        <key>
            <column name="ATTRIBUTE_SET_TYPE_ID" />
        </key>
        <many-to-many
            class="com.biofrontera.discovery.hibernate.Enumeration"
        >
            <column name="ENUMERATION_ID" />
        </many-to-many>
    </set>

    <!-- uni-directional many-to-many association to ParameterInfo -->
    <set
        name="parameterInfos"
        lazy="false"
      cascade="none"
        table="MM_ATT_SET_TYPE_PARAM_INFO"
    >
        <key>
            <column name="ATTRIBUTE_SET_TYPE_ID" />
        </key>
        <many-to-many
            class="com.biofrontera.discovery.hibernate.ParameterInfo"
        >
            <column name="PARAMETER_NAME" />
            <column name="PARAMETER_TYPE" />
        </many-to-many>
    </set>

</class>
</hibernate-mapping>


if I remove "outer-join="true"" for enumerations association only one record will be returned (as it should).

There is only one record in the ATTRIBUTE_SET_TYPE table. There are 3 corresponding entries in the Enumeration table.

Also I use the following params:

use_outer_join=true
hibernate.max_fetch_depth=3
hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 7:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is expected. Either set FetchMode.LAZY for the association, or setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) or distinctify the result yourself.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 7:12 am 
Newbie

Joined: Sun Apr 04, 2004 6:19 am
Posts: 15
michael wrote:
This is expected. Either set FetchMode.LAZY for the association, or setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) or distinctify the result yourself.


Rather strange decision by Hibernate team... :-/

What does lazy="true" together with outer-join="true" mean? ^^

It is somewhat frustrating that tweaking the config might require to change the code...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 9:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
What does lazy="true" together with outer-join="true" mean? ^^


you should have started here.... read hibernate in action, you'll understand ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: I still don't get it
PostPosted: Fri Dec 17, 2004 10:18 am 
Newbie

Joined: Thu Dec 02, 2004 3:51 pm
Posts: 8
anthony-

I have read hibernate in action, and I still don't get it. From what I have read turning lazy="true" and outer-join="true" in the config file for a mapping shouldn't have had that effect.

What I understand is that setting lazy to true means that hibernate does not attempt to call association until it is requested in the code. (Meaning I can map pieces to a object, define them as lazy, and in cases where I know i don't need to show them Hibernate won't build them).

Outer-join, from my understanding, is exactly that. It specifies to the DB to execute the query using outer-join. (which in my case in the posting below, I have to have becuase not every parent will have a child.)

But that doesn't explain why the parent record is in this mapping is getting duped.

http://forums.hibernate.org/viewtopic.p ... 5f9441146a

This is a posting I had on this topic a day ago. Please, help me figure out what i am not understanding, becuase at this I am about to recommend that my office not move to hibernate becuase it has so many "quirks" that you have to configure around.


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