JPA 2.0 JTA

Java Persistence API Job Task Analysis

Please review this Job Task Analysis and provide input by adding your comments to this wiki. Please also complete the short survey at: JPA Survey

Create a Java technology program that uses a RDMS for persistence

Task: Design a Java application that uses a RDMS

  1. Identify the applicability of JDBC and ORM as database access solutions.
  2. Select JDBC Statements, PreparedStatements, or CallableStatements for use in an application given a variety of design requirements and database usage.
  3. Plan the implementation of a JPA data access solution
    1. Analyse any existing database schema
    2. Select a JPA provider
    3. Design the classes to be used as Entity classes
      1. Identify primary keys
      2. Identify relationships between classes (how does the placement of foreign key columns vs join tables impact Entity relationships)
      3. Select a class hierarchy
      4. Choose field, property, or field+property persistence (JPA 2.0)
    4. Identify relevant design patterns

Task: Create basic JPA Entity classes

  1. Create Java classes
  2. Configure Java classes as JPA Entity classes
    1. Correctly apply the @Entity annotation to Java classes
  3. Map Entity classes to the structure of a RDMS
    1. Map Entity classes to database tables
      1. Correctly apply the @Table annotation to Java classes
      2. Create an orm.xml to provide table mapping information
    2. Map persistent fields and properties to database column
      1. Choose Java data types that are compatible to SQL column types
      2. Apply the @Lob annotation (make sure developers know what a String maps to by default)
      3. Correctly apply the @Id annotation to Java classes
      4. Select a primary key generation strategy if needed (this is database dependent and may require schema generation)
      5. Correctly apply the @Column annotation to Java classes
      6. Correctly apply the @Temporal annotation to Java classes
      7. Add column mapping information to an orm.xml file
    3. Use the @Transient annotation to prevent mapping
    4. Use the @Access annotation to control field and/or property based persistence (JPA 2.0)

Task: Utilize Entity classes by creating code that uses the EntityManager API

  1. Choose between Application-managed and Container-managed persistence context
  2. Identify the ideal placement of EntityManager code (why would you use a Sevlet vs Session EJB vs other)
  3. Obtain an entity manger
    1. Use dependency injection to obtain an entity manager with the @PersistenceContext annotation
    2. Use JNDI to obtain an entity manager
    3. Create an entity manager with the EntityManagerFactory API
  4. Use the JPA QL to retrieve a List of Entity object
  5. Use the Java Persistence Criteria API to retrieve Entity objects (JPA 2.0)
  6. Utilize Entity classes throughout their various lifecycle states, including the new, managed, detached, and removed states

Task: Use JPA relationships

  1. Use the @OneToOne, @ManyToOne, @OneToMany, and @ManyToMany annotations
  2. Select uni-directional or bi-directional relationships by the placement of the relationship annotations
  3. Add the mappedBy element to the OneToOne, OneToMany, or ManyToMany annotations to correctly map the inverse side of the relationship
  4. Apply the cascade=PERSIST, cascade=REMOVE, cascade=ALL, cascade=DETACH(JPA 2.0), cascade=MERGE, cascade=REFRESH elements to the relationship annotations
  5. Apply orphan removal to the @OneToOne and @OneToMany annotations (JPA 2.0)
  6. Use the @OrderColumn annotation to create ordered Lists (JPA 2.0)
  7. Use collections of non-entities with the @ElementCollection and @CollectionTable annotations (JPA 2.0)
  8. Customize relationship mapping with the @JoinColumn / @JoinColumns, @JoinTable annotations

Task: Use advanced JPA features

!!!! THESE ITEMS SHOULD BE WEIGHTED INDIVIDUALLY TO DETERMINE COVERAGE IN EXAMS AND COURSES !!!!

  1. Correctly apply the @MappedSuperclass annotation to Java classes
  2. Create composite primary keys (cover new features in JPA 2.0)
  3. Use embedded classes
  4. Model relationships as java.util.Map's
  5. Correctly use collections of basic and embeddable types (JPA 2.0)
  6. Use nested embedded classes (JPA 2.0)
  7. Use embedded classes with relationships (JPA 2.0)
  8. Override mappings for embeddables with @AttributeOverride
  9. Override mappings for embeddables with @AssociationOverride (JPA 2.0)
  10. Use maps to model ternary relationships (JPA 2.0)
  11. Correctly apply the @Inheritance annotation to Java classes

Task: Ensure data integrity by using Transaction and Locking

  1. Use JTA to manage transactions
    1. Use JTA in the EJB tier (little overlap here with EJBs)
    2. Use JTA in the web tier (little overlap here with Servlets)
  2. Identify bean managed transaction statements (little overlap here with EJBs)
  3. Use the EntityTransaction API
  4. Select a locking strategy (optimistic or pessimistic)
    1. Add the @Version annotation to Entity classes to enable optimistic locking
      1. Select the appropriate data types for use with the @Version annotation
    2. Acquire pessimistic lock with the entity manger lock method and various LockModeType values
  5. Make use of Persistence Context propagation (little overlap here with EJBs)
  6. Use container-managed extended PCs (little overlap here with EJBs)

Task: Apply Entity Listeners and Callback Methods

  1. Create life cycle methods
  2. Apply annotations to life cycle methods: @PrePersist, @PostPersist, @PreRemove, @PostRemove, @PreUpdate, @PostUpdate, and @PostLoad

Task: Create error handling code

  1. Identify how the parent class of PersistenceException impacts try/catch requirements and transaction behaviour
  2. Write code that handles the generation of PersistenceException sub classes and when it would be needed
  3. Identify when transactions might be rolled back vs when statements might be rolled back (JPA 2.0)

Task: Optimize database access

  1. Apply the @Basic annotation with fetch=LAZY or fetch=EAGER (ensure knowledge of the defaults for fields/properties and relationships)
  2. Create mass update and removal operations using the JPA QL
  3. Configure second-level caching using JPA portable methods (JPA 2.0)

Task: Configure and package JPA Entity classes in enterprise modules

  1. Place Entity classes in ear,war, and jar archives
    1. Create shared library jars with Entity classes
    2. Place persistence.xml and orm.xml in the correct module
      1. Modify the persistence.xml file given the placement of it and the Entity classes
    3. Identify differences in the persistence.xml file when using an application-managed vs a container-managed persistence context

Content Analysis

This section lists technologies that may not be fully utilized in a single task but should have adequate coverage.

Java Persistence Criteria API

  • Select between the type-safe API and string based methods (coverage of all Criteria API tasks should focus more on the type-safe API)
  • Obtain a reference to QueryBuilder object through EntityManager.getQueryBuilder or EntityManagerFactory.getQueryBuilder.
  • Create a CriteriaQuery object through the QueryBuilder instance.
  • Create a query root for a particular entity by invoking the QueryBuilder.from method.
  • Develop queries based on the query root that:
    • Select entities.
    • Traverse the relationships of the entity.
    • Restrict the query using the conditional methods of the QueryBuilder interface.
    • Contain subqueries.
    • Use parameters.
    • Uses CriteriaQuery.groupBy and CriteriaQuery.having to partition the query result into groups.
    • Orders the query results.

Bean Validation

Linda DeMichiel: I would keep this pretty basic, since JPA does not require use of bean validation. I'd probably orient this more around "identify" type questions.

  • Use the Bean Validation annotations to:
    • Specify that an entity property/field should not be null.
    • Set the maximum size of an entity's String field/property.
    • Set the numeric precision on integer and fraction field/properties.
    • Set the scale for decimal field/properties.
    • Set the minimum and maximum values for numeric fields/properties.
    • Specify whether the a temporal field/property should be in the past or the future.

Java Persistence Query Language

  1. Develop queries that use the SELECT clause to determine query results, including the use of entity types, use of aggregates, and returning multiple values.
  2. Develop queries that use Java Persistence Query Language syntax for defining the domain of a query using JOIN clauses, IN, and prefetching.
  3. Use the WHERE clause to restrict query results using conditional expressions, including the use of literals, path expressions, named and positional parameters, logical operators, the following expressions (and their NOT options): BETWEEN, IN, LIKE, NULL, EMPTY, MEMBER [OF], EXISTS, ALL, ANY, SOME, and functional expressions.
  4. Develop Java Persistence Query Language statements that update a set of entities using UPDATE/SET and DELETE FROM.
  5. Declare and use named queries, dynamic queries, and SQL (native) queries.
  6. Obtain javax.persistence.Query objects and use the javax.persistence.Query API.
  7. Use subqueries
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact