Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » jpa2.1 join on Criteria API(how to implement the JPQL using Criteria API)
jpa2.1 join on Criteria API [message #1079846] Mon, 05 August 2013 02:37 Go to next message
ma soot is currently offline ma soot
Messages: 3
Registered: August 2013
Junior Member
hi,

I have 2 entitis: TUser{id, name}, TUserFriend{id, userId, name}
the 2 talbe has PK but NO FK and NO one to many relation.

the new eclipselink2.5, i can run useing JPQL
"select u from TUser u join TUserFriend uf on u.id = uf.userId".

but i don't know how to implement using Criteria API.

Can u help me? Thanks a lot!

Soot.

Re: jpa2.1 join on Criteria API [message #1080571 is a reply to message #1079846] Tue, 06 August 2013 01:27 Go to previous messageGo to next message
ma soot is currently offline ma soot
Messages: 3
Registered: August 2013
Junior Member
None?
Re: jpa2.1 join on Criteria API [message #1080879 is a reply to message #1080571] Tue, 06 August 2013 09:40 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1016
Registered: July 2009
Senior Member
The JPA 2.1 javax.persistence.criteria.Join interface defines 'on' methods you can use to get the same behavior:

CriteriaBuilder qb = jpaEM.getCriteriaBuilder();
CriteriaQuery<Employee>cq = qb.createQuery(Employee.class);
Root<Employee> root = cq.from(Employee.class);
Join address = root.join("manager", JoinType.LEFT).join("address", JoinType.LEFT);
address.on(qb.equal(address.get("city"), "Ottawa"));
cq.where(qb.isNotNull(address.get("postalCode")));

If not using JPA 2.1, you will need to cast to EclipseLink's JoinImpl class to access the 'on' methods, added in EclipseLink 2.5.

Re: jpa2.1 join on Criteria API [message #1081407 is a reply to message #1080879] Wed, 07 August 2013 03:41 Go to previous messageGo to next message
ma soot is currently offline ma soot
Messages: 3
Registered: August 2013
Junior Member
Thanks for Chris!
But this isn't what I want.

select u from TUser u join TUserFriend uf on u.id = uf.userId

Bz. NO FK, I want to define the relation using "on" : on u.id = uf.userId

the follow is eclipse doc
http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/j_on.htm#on

Usage

EclipseLink supports using the ON clause between two root level objects.

I just want to define the relation between two root level object. using JPQL, It's OK, but can't using Criteria API.
Re: jpa2.1 join on Criteria API [message #1082398 is a reply to message #1081407] Thu, 08 August 2013 10:17 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Criteria does not support this.

If you can't use JPQL, then you could use EclipseLink Expressions, which do support this, or mix them with the Criteria API.

http://java-persistence-performance.blogspot.com/2012/05/jpql-vs-sql-have-both-with-eclipselink.html


James : Wiki : Book : Blog : Twitter
Previous Topic:Eclipselink 2.4 migration to openJPA (WebSphere 8.5.5 javax.persistence)
Next Topic:RCP / EclipseLink(Gemini) Example ??
Goto Forum:
  


Current Time: Fri Jul 25 14:23:31 EDT 2014

Powered by FUDForum. Page generated in 0.02739 seconds