3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3
4. WebLogic Java Developer Webcast1. Data Access with JPA Shaun SmithProduct Manager—Oracle TopLinkSohailDadaniSr. Sales Consultant
5. Java Persistence API (JPA)—in a Nutshell Defines: How Java objects are stored in relational A programmer API for reading, writing, and querying persistent Java objects (“Entities”) A full featured query language in JP QL a container contract that supports plugging any JPA runtime in to any compliant container Java SE/EE Application Java Classes JPA Provider JDBC Driver PersistenceDescriptors Database Schema
6. JPA—Background A standardization of industry practices for Java POJO Object Relational Persistence Developed as part of the EJB 3.0 specification but now spun off into its own specification (JSR 317) Suitable for use in different modes Standalone in Java SE environment Hosted within a Java EE Container Merging of expertise from persistence vendors and communities including: TopLink, Hibernate, JDO, EJB vendors and individuals
7. Oracle TopLink 11gR1 Oracle’s Enterprise Java Persistence Framework Includes open source EclipseLink with Commercial Support Certified on and part of the Oracle WebLogic application server Includes TopLink Grid: JPA integration with Coherence Supports scaling JPA applications into very large clusters Development tool support in Eclipse OEPE, JDeveloper, and NetBeans
8. Customer id: int name: String creditRating: int CUST Object-Relational Mapping The activity of ‘Mapping’ is the process of connecting objects/attributes to tables/columns ID NAME C_RATING
9. Mapping with Annotations @Entitypublic class Customer { @Id private Stringname; @OneToOne private Account account; public String getName() { return name; } public voidsetName(String name) { this.name = name; } public Account getAccount() { return account; } public void setAccount(Account account) { this.account = account; } }
10. Mappings with XML <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" … <entityclass=“Customer"> <attributes> <idname=“name“/> <one-to-onename=“account“/> </attributes> </entity> … </entity-mappings>
11. Typical Development Approaches Bottom Up Start from a database schema and generate JPA entities A good way to bootstrap a project if you’re building on an existing database Top Down Generate database schema from JPA entities A good way to get started in a green field development—focus on developing a good Java domain model Meet in the Middle Map Java classes to an existing database schema Maps optimized Java domain model to an optimized database schema—typically follows Bottom Up and Top Down
12. Our Development Scenario Building a simple JAX-RS fronted Java application that interacts with a relational database Starting from an XSD that describes the documents the system must support Technologies we’ll use: JPA, JAXB, and JAX-RS Development Approach: Use JAXB Schema compiler to generate JAXB annotated POJOS Follow JPA “Top Down” approach by defining JPA mappings for generated classes and then generating a database schema from those mapped classes.