Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPQL problems with JOIN FETCH on List<Entity>
JPQL problems with JOIN FETCH on List<Entity> [message #1061964] Wed, 05 June 2013 07:41 Go to next message
F C is currently offline F CFriend
Messages: 12
Registered: June 2013
Junior Member
Hi,
I use EclipseLink 2.4 and JPA 2.0.
I have the following entities:

@Entity
@Table(name = "EMPLOYERS")
public class Employer implements Serializable {
...
@Id
@Column(name="ID")
private String id;

private String name;

private String surname;

@OneToMany(mappedBy="employer", fetch=FetchType.EAGER)
private List<Employee> list;
...
}

and

@Entity
@Table(name = "EMPLOYEES")
public class Employee implements Serializable {
...

@ManyToOne
@JoinColumn(name="ID", insertable=false, updatable=false)
private Employer employer;

...
}

Now, my jpql is:
StringBuilder query = new StringBuilder();
query.append("SELECT employer FROM Employer employer ");
query.append("JOIN FETCH employer.list list ");
query.append("WHERE ");
query.append("UPPER(employer.id) = ?1 ");

So, the generated SQL query is:
/* Formatted on 2013/06/05 09:16 (Formatter Plus v4.8.Cool */
SELECT ....
FROM employees t0, employees t2, employers t1
WHERE ( (UPPER (t1.id) = ?)
AND ((t0.id = t1.id) AND (t2.id = t1.id)
)
)

So, i can't understand why in FROM clause table EMPLOYEES appears two times.
Can someone help me?
Re: JPQL problems with JOIN FETCH on List<Entity> [message #1062077 is a reply to message #1061964] Wed, 05 June 2013 18:25 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I can't tell from what was provided - are there any other Employer-Employee relationships? Is T0, T2 or both appearing in the select statement?
Re: JPQL problems with JOIN FETCH on List<Entity> [message #1062970 is a reply to message #1062077] Tue, 11 June 2013 14:44 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You define your tables as uppercase, but the SQL you included is lower case, so either this is not the real code you are using, or not the real SQL that was generated?


James : Wiki : Book : Blog : Twitter
Previous Topic:NamedQuery of name ... not found.
Next Topic:EclipseLink 1.x on JBoss 7
Goto Forum:
  


Current Time: Fri Apr 19 22:47:35 GMT 2024

Powered by FUDForum. Page generated in 0.02785 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top