• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Difference between persistence field and association field

 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic