Eclipselink jpa black belt course
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

EclipseLink JPA Black Belt Course PowerPoint PPT Presentation


  • 58 Views
  • Uploaded on
  • Presentation posted in: General

EclipseLink JPA Black Belt Course. Section 3: Advanced Mapping. EclipseLink JPA - Mappings. Common Mapping options Relationship Mappings Inheritance Optimistic Locking. BasicMap & BasicCollection.

Download Presentation

EclipseLink JPA Black Belt Course

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Eclipselink jpa black belt course

EclipseLink JPABlack Belt Course

Section 3: Advanced Mapping


Eclipselink jpa mappings

EclipseLink JPA - Mappings

  • Common Mapping options

  • Relationship Mappings

  • Inheritance

  • Optimistic Locking


Basicmap basiccollection

BasicMap & BasicCollection

  • @BasicMap - stores a collection of key-value pairs of simple types, such as String, Number, Date, etc., in a single table

  • @BasicCollection - stores a collection of simple types

    • Example: Responsibility list on Employee class

“Code”

Employee

id-=7

“Documentation”

responsibilities

“Test”

“Social Events”


Basiccollection database tables

BasicCollection Database Tables

EMPLOYEE

FK relationship

RESPONS

Primary keys


Converters

Converters

  • New converter mappings for type conversion and user defined types include:

    • @Converter

    • @TypeConverter

    • @ObjectTypeConverter

    • @StructConverter

    • @Convert

      @[email protected](

      name="Currency",

      converterClass=CurrencyConverter.class)[email protected]("Currency")privateCurrencysalaryCurrency;


Type converter

joe: Employee

Integer id;

Date joinDate;

String name;

Type Converter

  • Converts from a Java type to specific database type

    • For example: String NUMERIC in the database

    • For example: StringDATE in the database

    • Actual value is not transformed, just the type

EMP_ID

J_DAY

Name

2661

Jeb

‘11/13/95’

‘04/01/93’

Jake

2662

java.util.Date

java.sql.Date

Mindy

‘08/01/96’

2663


Objecttype converter

ObjectType Converter

  • Used to match a fixed number of database primitive values to Java objects

  • Set up a hashtable of keys and values, e.g.

    • “M” = “Male”

    • “F” = “Female”


Objecttype converter example

ObjectType Converter Example

@ObjectTypeConverter(name="gender-converter",objectType = model.Gender.class,conversionValues = [email protected](dataValue="M", objectValue = "Male"),@ConversionValue(dataValue="F", objectValue = "Female")})

@Entitypublicclass Employee { [email protected]("gender-converter")private Gender gender = Gender.Male;

publicenum Gender {

Female, Male, ;

}


Transformation mapping

Transformation Mapping

  • Used when:

    • No other mappings are appropriate (extremely flexible)

    • The user has complete control over how data gets written to and read from database rows

  • The user must provide several methods to define a transformation mapping

    • Given raw database row, return a value to populate the attribute in question

    • One separate method for every database field to be populated

      • Each method returns a value to populate the field, given the object to be written


Transformation mapping example

Transformation Mapping Example

  • Attribute value is a sum of database fields

  • Attribute value is an array of fields

Attribute transformation method/class

Employee class

Vector normalHours;

S_TIME

EMP_ID

E_TIME

String firstName;

Integer id;

Field transformation method/class

2661

07:00

15:30

2662

07:00

15:30

Field transformation method/class

2663

15:30

24:00


Customizers

Customizers

  • Use the @Customizer EclipseLink annotation to register a class that can customize the mappings for an Entity using the EclipseLink native API.

    @[email protected](EmployeeCustomizer.class)publicclassEmployeeimplementsSerializable{...

    publicclassEmployeeCustomizer

    implementsDescriptorCustomizer{publicvoidcustomize(ClassDescriptorDescriptor)

    throwsException{


Returning policy

Returning Policy

  • Return policy options can be configured using:

    • @ReturnInsert

    • @ReturnUpdate

    • On the Oracle Database, specifying an @ReturnInsert or @ReturnUpdate will add a RETURNING clause to insert and update statements to efficiently reread modified data.

    • On databases other than Oracle, the underlying ReturningPolicy can be configured using a descriptor customizer.

      @EntitypublicclassEmployeeimplementsSerializable{...@[email protected];


Other mappings

Other Mappings

  • Other advanced mappings supported by TopLink 11g include:

    • @PrivateOwned - supports orphan management

    • @JoinFetch - enables the joining and reading of a referenced object(s) in the same query as the source object

    • @Mutable - indicates that the value of a complex field itself can be changed or not changed (instead of being replaced)

    • @VariableOneToOne - supports OneToOne mappings to an interface rather than an Entity

    • @ReadOnly - makes an Entity read only


Eclipselink jpa mappings summary

EclipseLink JPA Mappings Summary

  • JPA 1.0 covers the bulk of what is needed

    • + Additional EclipseLink Mappings and options

    • Mapping extensions are useful but require native API or XML

  • JPA 2.0 will address several common extensions

    • Element Collection/Map to handle BasicCollection/Map

    • Map with key and values being embeddable, basic, or entity

    • @MapsId to avoid redundant id fields

    • Basically standardizing common extensions


  • Login