-->
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: Same Object returned multiple times
PostPosted: Fri Jan 06, 2006 3:05 pm 
Beginner
Beginner

Joined: Wed Dec 14, 2005 10:32 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

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

<hibernate-mapping>
<class name="com.common.OrderDetail" table="ORDER_DTL"
dynamic-insert="false"
dynamic-update="false"
batch-size="10">

<id name="ordNum" type="string" column="ORDER_NUM" >
<generator class="native"/>
</id>

<property name="versionNum" insert="false" update="false">
<column name="VERSION_NUM "/>
</property>

<property name="ordNum" insert="false" update="false">
<column name="ORDER_NUM "/>
</property>

<property name="dtlLineNum" insert="false" update="false">
<column name="DTL_LINE_NUM"/>
</property>

<property name="prdLineId" insert="false" update="false">
<column name="PRODUCT_LINE_ID" />
</property>
<property name="dtlStatusCd" insert="false" update="false">
<column name="DTL_STATUS_CD"/>
</property>


</class>

</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
Criteria criteria = session.createCriteria(OrderDetail.class);
criteria.add(Expression.eq("ordNum",orderNum ));
// criteria.add(Expression.eq("dtlStatusCd", "NEW "));
// criteria.add(Expression.eq("dtlLineNum", new Integer(1)));
List results = criteria.list();

log.debug("Successfull" + results.size());
for(int i=0; i<results.size();i++){
OrderDetail od1 = (OrderDetail)results.get(i);
log.debug(od1.toString());
}
tx.commit();


Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle9i

The generated SQL (show_sql=true):
select this_.ORDER_NUM as ORDER1_0_, this_.VERSION_NUM as VERSION2_1_0_, this_.ORDER_NUM as ORDER3_1_0_, this_.DTL_LINE_NUM as DTL4_1_0_, this_.PRODUCT_LINE_ID as PRODUCT5_1_0_, this_.DTL_STATUS_CD as DTL6_1_0_ from OEOM_ABS_ORDER_DTL this_ where this_.ORDER_NUM=?


Debug level Hibernate log excerpt:

My order Detail Table has 3 columns as primiary keys:

CONSTRAINT OEOM_ABS_ORDER_DTL_PK PRIMARY KEY (ORDER_NUM, VERSION_NUM, DTL_LINE_NUM)


In the mapping file I defined 'id' element to be only the OrderNumber;

Now when I try to retireve the Order Detail obejcts as shown in the above java code it returns the same object 3 times instead of giving 3 different objects.

When I ran the generated SQL in the database with the same order number I used in the java code it gives me 3 different rows but the list has same object(the first one) 3 times.

What do I need to do to overcome this??

Thanks in advance.

-Ram


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 3:24 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
is your toString() method only displaying a few attributes which could be the same across objects?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 5:00 pm 
Beginner
Beginner

Joined: Wed Dec 14, 2005 10:32 am
Posts: 20
I could see the same addresses being printed.

I found the solution: Need to implement java.io.serializable. So that it does not put the same object.


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Thu Apr 29, 2010 12:40 pm 
Newbie

Joined: Thu Apr 29, 2010 12:24 pm
Posts: 1
Hi, I am new to this board but could not find any other information about this issue. I am having the same problem and tried to implement Serializable (I would assume that you do that on the mapped bean) but it did not affect the results.

I am using Hibernate 3 with a Spring config file, but that should all be wired up correctly because I have other beans and queries working correctly. My SQL comes out ok when I have show_sql=true, and when I put the generated SQL into another query tool, I get the correct result set. But running it through hibernate and my java app returns the correct number of rows but with the first row repeated for every row.

The main difference with my setup and the previous poster is that I am using a subselect in my mapping file to join and limit the column output of two tables, and then making the mapping off of the resulting table.

I can post whatever I need to on here, let me know if anyone has any ideas.
Any help is much appreciated.


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Wed Oct 06, 2010 12:51 pm 
Newbie

Joined: Wed Oct 06, 2010 12:49 pm
Posts: 8
bjaminwiz wrote:
Hi, I am new to this board but could not find any other information about this issue. I am having the same problem and tried to implement Serializable (I would assume that you do that on the mapped bean) but it did not affect the results.

I am using Hibernate 3 with a Spring config file, but that should all be wired up correctly because I have other beans and queries working correctly. My SQL comes out ok when I have show_sql=true, and when I put the generated SQL into another query tool, I get the correct result set. But running it through hibernate and my java app returns the correct number of rows but with the first row repeated for every row.

The main difference with my setup and the previous poster is that I am using a subselect in my mapping file to join and limit the column output of two tables, and then making the mapping off of the resulting table.

I can post whatever I need to on here, let me know if anyone has any ideas.
Any help is much appreciated.



Did you figure this out? I am having the same issue and I'm at my wits end.


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Thu Oct 07, 2010 10:58 am 
Newbie

Joined: Wed Oct 06, 2010 12:49 pm
Posts: 8
Here are some details on my issue that bjaminwiz also had. I've aged 10 years in one day trying to figure this out.

The Parent class join field
Code:
@OneToMany()
    @JoinColumn(name = "EMP_ID")
    public Set<TeamMemberAuthLimits> getAuthLimits() {       
        return authLimits;
    }


Child class fields
Code:
@Id
    @Column(name = "EMP_ID", updatable = false, unique = false)
    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(String empId) {
        this.employeeId = empId;
    }

    @Column(name = "AUTH_LIMIT_TYPE", updatable = false)
    public String getAuthLimitType() {
        return authLimitType;
    }

    public void setAuthLimitType(String authLimitType) {
        this.authLimitType = authLimitType;
    }

    @Column(name = "AUTH_LIMIT_AMOUNT", updatable = false)
    public BigDecimal getAuthLimitAmt() {
        return authLimitAmount;
    }

    public void setAuthLimitAmt(BigDecimal authLimitAmount) {
        this.authLimitAmount = authLimitAmount;
    }


SQL statement hibernated generated, which does return the correct data when I run against the database using a SQL tool:
Code:
Hibernate: select authlimits0_.EMP_ID as EMP1_1_, authlimits0_.EMP_ID as EMP1_19_0_, authlimits0_.AUTH_LIMIT_AMOUNT as AUTH2_19_0_, authlimits0_.AUTH_LIMIT_TYPE as AUTH3_19_0_ from COMMON.T_TEAM_MEMBER_AUTH_LIMITS authlimits0_ where authlimits0_.EMP_ID=?


Trace ouput

Notice the "[TRACE] CollectionLoadContext: found loading collection bound to current result set processing; reading row"

It appears that hibernate is only hydrating the first row, then it uses that same row to populate the rest??? WTF?

Code:
[2010-10-07 09:57:27,600] [TRACE]  AbstractBatcher: preparing statement
[2010-10-07 09:57:27,616] [TRACE]  StringType: binding '00000444197' to parameter: 1
[2010-10-07 09:57:28,678] [DEBUG]  AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
[2010-10-07 09:57:28,678] [DEBUG]  Loader: result set contains (possibly empty) collection: [com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]
[2010-10-07 09:57:28,678] [TRACE]  LoadContexts: constructing collection load context for result set [oracle.jdbc.driver.OracleResultSetImpl@1f8aad]
[2010-10-07 09:57:28,678] [TRACE]  CollectionLoadContext: starting attempt to find loading collection [[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]]
[2010-10-07 09:57:28,678] [TRACE]  LoadContexts: attempting to locate loading collection entry [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] in any result-set context
[2010-10-07 09:57:28,678] [TRACE]  LoadContexts: collection [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] not located in load context
[2010-10-07 09:57:28,694] [TRACE]  CollectionLoadContext: collection not yet initialized; initializing
[2010-10-07 09:57:28,694] [TRACE]  Loader: processing result set

[2010-10-07 09:57:28,694] [DEBUG]  Loader: result set row: 0
[2010-10-07 09:57:28,694] [TRACE]  StringType: returning '00000444197' as column: EMP1_19_0_
[2010-10-07 09:57:28,694] [DEBUG]  Loader: result row: EntityKey[com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:28,694] [TRACE]  Loader: Initializing object from ResultSet: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:28,694] [TRACE]  AbstractEntityPersister: Hydrating entity: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE] BigDecimalType: returning '50000000' as column: AUTH2_19_0_
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning 'AUTH000248' as column: AUTH3_19_0_
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning '00000444197' as column: EMP1_1_
[2010-10-07 09:57:29,256] [DEBUG]  Loader: found row of collection: [com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  CollectionLoadContext: starting attempt to find loading collection [[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]]
[2010-10-07 09:57:29,256] [TRACE]  LoadContexts: attempting to locate loading collection entry [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] in any result-set context
[2010-10-07 09:57:29,256] [TRACE]  LoadContexts: collection [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] located in load context
[2010-10-07 09:57:29,256] [TRACE]  CollectionLoadContext: found loading collection bound to current result set processing; reading row
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning '00000444197' as column: EMP1_1_
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: loading entity: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: attempting to resolve: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: resolved object in session cache: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [DEBUG]  Loader: result set row: 1
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning '00000444197' as column: EMP1_19_0_
[2010-10-07 09:57:29,256] [DEBUG]  Loader: result row: EntityKey[com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning '00000444197' as column: EMP1_1_
[2010-10-07 09:57:29,256] [DEBUG]  Loader: found row of collection: [com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  CollectionLoadContext: starting attempt to find loading collection [[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]]
[2010-10-07 09:57:29,256] [TRACE]  LoadContexts: attempting to locate loading collection entry [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] in any result-set context
[2010-10-07 09:57:29,256] [TRACE]  LoadContexts: collection [CollectionKey[com.wellsfargo.wmg.tpl.domain.user.TeamMember.authLimits#00000444197]] located in load context
[2010-10-07 09:57:29,256] [TRACE]  CollectionLoadContext: found loading collection bound to current result set processing; reading row
[2010-10-07 09:57:29,256] [TRACE]  StringType: returning '00000444197' as column: EMP1_1_
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: loading entity: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: attempting to resolve: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [TRACE]  DefaultLoadEventListener: resolved object in session cache: [com.wellsfargo.wmg.tmm.domain.TeamMemberAuthLimits#00000444197]
[2010-10-07 09:57:29,256] [DEBUG]  Loader: result set row: 2


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Thu Oct 07, 2010 1:45 pm 
Newbie

Joined: Wed Oct 06, 2010 12:49 pm
Posts: 8
A link to somene who had my exact problem: http://opensource.atlassian.com/project ... wse/HB-701

Anyone? Anyone?

Buehler?


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Fri Oct 08, 2010 9:33 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Once again. You should always use unique IDs for your collection entities. See also my answer there: viewtopic.php?f=1&t=1006384

This is not a bug, but normal behavior. You can use row numbers as your identifiers if you are so eager to use non-unique elements.


Top
 Profile  
 
 Post subject: Re: Same Object returned multiple times
PostPosted: Fri Oct 08, 2010 10:18 am 
Newbie

Joined: Wed Oct 06, 2010 12:49 pm
Posts: 8
Thank you!!!!!!!!!!


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.