DN v5 : JPQL FROM JOIN to another “root” entity

A vendor extension now available in DataNucleus v5 is for JPQL’s ability to JOIN to other entities. In standard JPQL you can only add a JOIN through a relation. For example

SELECT p FROM Person p 
    JOIN p.address a WHERE a.street = 'Main Street'

In this example we have a candidate “root” entity of Person, and are joining to the Address entity via the “address” relation field in Person.

The vendor extension provides the ability to join to a new “root” entity. For example

SELECT p FROM Person p 
    LEFT OUTER JOIN Address a ON p.addressName = a.name

In this example we have a candidate “root” entity of Person, and we are joining to the Address entity using a manually specified ON clause. That is, there doesn’t need to be a relation between Person and Address to make this join, just a condition that we are imposing in the ON clause.

This is not part of the JPA 2.1 spec, but may be in a future JPA spec, but you can make use of it in DataNucleus v5+.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s