aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Difference between persistence field and association field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Difference between persistence field and association field" Watch "Difference between persistence field and association field" New topic
Author

Difference between persistence field and association field

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1162
    
    1

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


Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
Tomas Klubal
Greenhorn

Joined: Aug 16, 2004
Posts: 20
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

Joined: Nov 10, 2005
Posts: 37
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Difference between persistence field and association field