Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Previous Topic:Eclipselink 2.4 migration to openJPA (WebSphere 8.5.5 javax.persistence)
Next Topic:RCP / EclipseLink(Gemini) Example ??
Goto Forum:
  


Current Time: Wed Jul 02 23:25:36 EDT 2025

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

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

Back to the top