-->
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.  [ 6 posts ] 
Author Message
 Post subject: Entity duplication despite ditinct in ejbql
PostPosted: Mon Mar 13, 2006 5:49 am 
Newbie

Joined: Wed Dec 28, 2005 2:44 pm
Posts: 8
With the following entities:

@Entity
@table(name="a")
public class A {
private int id;
private List<B> bs;

@Id
public int getId() {return id;}
public void setId(int pId){id = pId;}

@OneToMany(targetEntity=B.class, mappedBy="a")
public List<B> getBs() {return bs;}
public void setBs(List<B> pBs){bs = pBs;}
}

and


@Entity
@table(name="b")
public class B {
private int id;
private A a;

@Id
public int getId() {return id;}
public void setId(int pId){id = pId;}

@ManyToOne(targetEntity=A.class)
@JoinColumn(name="a")
public A getA() {return a;}
public void setA(A pA){a = pA;}
}

when the tables are:

a

id
------
1

b

id | a
---|---
1 | 1
2 | 1


one might expect that the query created from

SELECT DISTINCT a
FROM A a
LEFT JOIN FETCH a.bs

will return a list containing one entity.
Instead, the query returns a list containing twice the same instance of the entity, since it creates one entity for every row (although it doesn't recreates entities, so it is the same instance twice).
It seems like a bug.
It is possible to fix it in Loader (while populating the list), what should be done?

Hibernate version:3.1.rc2

Name and version of the database you are using:oracle9i

The generated SQL (show_sql=true):
select distinct a0_.id as id2_0_,
bs1_.id as id8_1_,
bs1_.a as a8_1_,
bs1_.a as a0__,
bs1_.id as id0__,
from a a0_ left outer join b bs1_ on a0_.id = bs1_.a


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 8:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is not a bug regarding the way SQL and hence EJBQL works.
But Steve has changed this behavior in hibernate core SVN trunk, you can try and use it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 9:54 am 
Newbie

Joined: Wed Dec 28, 2005 2:44 pm
Posts: 8
But EJBQL is a typed language, so how can It return the same instance twice, If I use "distinct"?
In the ejb-persistence spec (final draft) it is written: "The DISTINCT keyword is used to specify that duplicate values must be eliminated from the query result", so this behaviour does not match the (temporary) spec!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The spec has benn changed in this area :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 10:15 am 
Newbie

Joined: Wed Dec 28, 2005 2:44 pm
Posts: 8
Do you mean the ditinct does not mean what I said it means? The quote is from the "public final draft" the last version of the spec. Do you say it will be changed in the next version, or that it was changed and you haven't managed to match the change yet?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 8:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There are on going discussions on whether allowing distinct when a join is used.

_________________
Emmanuel


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