This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between persistence field and association field

 
Abhay Agarwal
Ranch Hand
Posts: 1375
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am reading EJB3 in Action book. I am on Chapter 10.
On page 373, under "Grouping with GROUP BY and HAVING section, it is written that

you can group by a single-value path expression that is either a persistence or association field.


I am not able to understand the difference between persistence field and association field.
Please tell me the difference

Thanks
 
Tomas Klubal
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sentence fom the book is not quite correct as you can have 2 types of persistent fields (according to the spec 2.1.1; 4.3): state-field or association-field.
The difference between those two is that association field points to another entity (type is the abstract
schema type of the related entity) and the state field does not (it is just some value of type valid for persistent fields).

Example for entities "Person p" and "Account a" is:
state-field: p.age
association-field: p.account
 
Umakanth Godavarthy
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The path expressions are clearly defined in ejb-spec (JSR 220) for JPA in section 4.4.4:

"single_valued_path_expression ::=
state_field_path_expression | single_valued_association_path_expression
state_field_path_expression ::=
{identification_variable | single_valued_association_path_expression}.state_field
single_valued_association_path_expression ::=
identification_variable.{single_valued_association_field.}*single_valued_association_field
collection_valued_path_expression ::=
identification_variable.{single_valued_association_field.}*collection_valued_association_field
state_field ::= {embedded_class_state_field.}*simple_state_fi"

The association fields are also part of the persistent state (driven by cascade element of the association) of an entity.
An important thing to note is JPQL is defined for an entity and its persistent state and NOT for transient or static fields.

So in this sense, the statement in EJB3 in Action is loosely defined for group by clause.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic