eclipselink jpa black belt course
Download
Skip this Video
Download Presentation
EclipseLink JPA Black Belt Course

Loading in 2 Seconds...

play fullscreen
1 / 14

EclipseLink JPA Black Belt Course - PowerPoint PPT Presentation


  • 109 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'EclipseLink JPA Black Belt Course' - caldwell-mcclain


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)publicclassEmployeeimplementsSerializable{@Convert("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 = {@ConversionValue(dataValue="M", objectValue = "Male"),@ConversionValue(dataValue="F", objectValue = "Female")})

@Entitypublicclass Employee { …@Convert("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]@ReturnUpdateprivateStringfirstName;

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
ad