codecamp iasi-26 nov 2011-what's new in jpa 2.0
TRANSCRIPT
![Page 1: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/1.jpg)
What’s new in JPA 2.0
Alin Burlacu
Java Developer @ Endava
25.11.2011
![Page 2: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/2.jpg)
Airplane view
Why ?
Serializable
JDBC
Platform independent
More OOP like
How ?
ORM (Object-Relational Mapping)
Entity manager
JPQL (Java Persistence Query Language)
![Page 3: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/3.jpg)
What’s new
Expanded mapping functionality
Pessimistic locking
Expanded QL
Criteria API
Cache (L2) like a standard (minimal)
![Page 4: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/4.jpg)
Expanded mapping functionality
@Access(Type Option)
Mix access modes in a hierarchy
Combine access modes in a single class
![Page 5: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/5.jpg)
Expanded mapping functionality
Access Type Option - CODE
![Page 6: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/6.jpg)
@Transient to prevent the field from being
mapped in addition to the property.
![Page 7: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/7.jpg)
Expanded mapping functionality
Orphan Removal
Only relationships with single cardinality on
the source side :
@OneToOne
@OneToMany
![Page 8: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/8.jpg)
Expanded mapping functionality
Orphan Removal - CODE
![Page 9: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/9.jpg)
Be aware of object lifecycle
![Page 10: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/10.jpg)
Expanded mapping functionality
@ElementCollection
Collections of simple data types mapped in
separate tables.
Map support has been extended so that
maps can have keys and values of basic
types, entities, or embeddables
![Page 11: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/11.jpg)
Expanded mapping functionality
@ElementCollection – CODE
(Collection of Basic Types)
![Page 12: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/12.jpg)
Expanded mapping functionality
@ElementCollection - CODE
(Map of Basic Types)
![Page 13: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/13.jpg)
Expanded mapping functionality
Other
@OrderColumn
@Embeded
@Embedable
@EmbededId
@OneToMany (no join Table)
Hierarchy of embedables
Relations to embedables
![Page 14: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/14.jpg)
![Page 15: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/15.jpg)
Pessimistic locking - CODE
![Page 16: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/16.jpg)
Pessimistic locking - CODE
![Page 17: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/17.jpg)
Expanded QL Timestamp literals
SELECT t from BankTransaction t
WHERE t.txTime > {ts „2008-06-0110:00:01.0‟}
IN expression may include collection parameter
SELECT emp FROM Employee emp
WHERE emp.project.id IN [:projectIds]
Non- polymorphic queries
SELECT e FROM Employee e
WHERE CLASS(e) = FullTimeEmployee OR
e.wage = “SALARY”
![Page 18: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/18.jpg)
Expanded QL
Ordered List indexing
SELECT t FROM CreditCard c
JOIN c.transactionHistory t
WHERE INDEX(t) BETWEEN 0 AND 9
CASE statement
UPDATE Employee e SET e.salary =
CASE e.rating WHEN 1 THEN e.salary * 1.1
WHEN 2 THEN e.salary * 1.05
ELSE e.salary * 1.01
END
![Page 19: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/19.jpg)
Criteria API
STRING-BASED CRITERIA - CODE
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery c =
b.createQuery(Account.class);
Root acct = c.from(Account.class);
c.select(acct) .where(
cb.equal(acct.get(“name”), “Jim”));
return em.createQuery(c).getResultList();
}
![Page 20: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/20.jpg)
Criteria API
STRONGLY TYPED CRITERIA - CODE
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Account> c =
cb.createQuery(Account.class);
Root<Account> acct = c.from(Account.class);
c.select(acct).where(
cb.equal(acct.get(Account_.name),
“Jim”));
Return em.createQuery(c).getResultList();
}
![Page 21: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/21.jpg)
Cache (L2) like a standard
(minimal)
![Page 22: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/22.jpg)
![Page 23: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/23.jpg)
References JSR 317 (http://jcp.org/en/jsr/detail?id=317)
ProJPA 2 Mastering the Java™ Persistence API by Mike Keith and Merrick Schincariol
Beginning Java™ EE 6 Platform with GlassFish™ 3 by Antonio Goncalves
http://www.infoq.com/presentations/whats-new-and-exciting-in-jpa-20
http://en.wikibooks.org/wiki/Java_Persistence/What_is_new_in_JPA_2.0%3F
http://wiki.eclipse.org/EclipseLink/Examples/JPA#JPA_2.0
http://www.developer.com/features/article.php/3892261/JPA-20-Cache-Vs-Hibernate-Cache-Differences-in-Approach.htm
![Page 24: Codecamp iasi-26 nov 2011-what's new in jpa 2.0](https://reader033.vdocuments.us/reader033/viewer/2022052323/559531121a28ab1f458b4622/html5/thumbnails/24.jpg)
Thank you