Java Persistence Query Language Flashcards
JPA
Java Persistence API
JP QL
Java Persistence Query Language
Object keyword
The keyword OBJECT can be used to indicate that the result type of the query is the entity bound to the identification variable. It has no impact on the query, but it can be used as a visual clue.
The syntax of the OBJECT keyword is limited to identification variables.
Supported for backward compatibility.
What is “projection” wrt JP QL?
The practice of reporting only a subset of the state fields from an entity is called projection.
What are “Constructor Expressions”.
Constructor Expressions are a form of the SELECT clause involving multiple expressions is the constructor expression, which specifies that the results of the query are to be stored using a user-specified object type.
The result object type must be referred to by using the fully qualified name of the object.
Identification Variables
The identification variable is the starting point for all query expressions. Every query must have at least one identification variable defined in the FROM clause, and that variable must correspond to an entity type.
Range Variable declaration
When an identification variable declaration does not use a path expression (that is, when it is a single entity name), it is referred to as a range variable declaration.
Range variable declarations use the syntax < entity_name > [AS] < identifier>.
identifier is case insensitive.
When does a join occur in JP QL?
Joins occur whenever any of the following conditions are met in a select query.
<ul>
<li>Two or more range variable declarations are listed in the FROM clause and appear in the select clause.</li>
<li>The JOIN operator is used to extend an identification variable using a path expression. </li>
<li>A path expression anywhere in the query navigates across an association field, to the same or a different entity. </li>
<li>One or more WHERE conditions compare attributes of different identification variables.</li>
</ul>
Inner Join
An inner join between two entities returns the objects from both entity types that satisfy all the join conditions.
Cartesian product.
Cartesian products are rare with JP QL queries given the navigation capabilities of the language, but they are possible if two range variable declarations in the FROM clause are specified without additional conditions specified in the WHERE clause.
What is downcasting?
Downcasting is the technique of making an expression that refers to a superclass be applied to a specific subclass . It is achieved through the use of the TREAT operator.