JPA 2.0What’s new?Emiel PaasschensRef. implemenatie van EclipseLink is bijlange (met name Criteria API) nanognietaf, dus…GEEN Hands-On of tochwel…
Programma Standard properties in persistence.xml
 Mixed @AccessType
 Derived Identifiers
 @ElementCollection
Undirectional @OneToMany / @OneToOne
 @OrderColumn
Shared Cache API
Locking
 JP QL
 Expression and criteria API
HandsOn?
Drankjeaan de barStandard properties for persistence.xmlSE only:javax.persistence.jdbc.driver 	fully qualified name of the driver class
javax.persistence.jdbc.url 	driver-specific URL
javax.persistence.jdbc.user 	username used by database connection
javax.persistence.jdbc.password 	password for database connection validation EE and SE:javax.persistence.lock.timeoutvalue in milliseconds for pessimistic lock timeout
javax.persistence.query.timeoutvalue in milliseconds for query timeout
javax.persistence.validation.group.pre-persist	groups that are targeted for validation upon the pre-persist event
javax.persistence.validation.group.pre-update	groups that are targeted for validation upon the pre-update event
javax.persistence.validation.group.pre-remove	groups that are targeted for validation upon the pre-remove eventMixed @AccessTypeProperty based or field based:@Access(FIELD)@Access(PROPERTY)
Can be mixed now! (instead of one or the other)At Entity/Class level the default Access type is defined
Can be set per attribute to differ from default: - on field (declaration) @Access(FIELD) access directly on instance variable by pers.prov.- on property (getter accessor) @Access(PROPERTY) access via accessor methods by pers. prov.
Be aware: @Access(PROPERTY):- validation/conversion logic in accessor methods is executed!- exceptions are catched and wrapped in PersistenceException, which is thrown. Transactions are marked for rollback.
The access type of an embeddable class is determined by the access type class in which it is embedded, independent of the containing class.Mixed @AccessType(code)@Entity@Access(FIELD)public class Vehicle {	@Id 	private Long id;	@Transient	double fuelEfficieny; 	@Access(PROPERTY)	@Column(name=”FUEL_EFF”)	public double getDbFuelEfficiency(){	return convertToMetric(fuelEfficieny);	} 	public void setDbFuelEfficiency(double d){fuelEfficieny= convertToImperial(d);	}}
Derived Identifiers (1)Old JPA 1.0 way: Identifiers that include a relationship
 Require an additional foreign key field
 Indicate one of the mappings as read only

JPA 2.0

Editor's Notes

  • #4 These defined properties must be implemented by each vendor (aside from vendor specific properties)
  • #6 Let op! Mark @Transient anderswordtdezewegens default FIELD access ookgepersisteerd.