Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 01052200BC8 for ; Wed, 23 Nov 2016 16:20:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id F37D5160AFB; Wed, 23 Nov 2016 15:20:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7BEEA160AFA for ; Wed, 23 Nov 2016 16:20:08 +0100 (CET) Received: (qmail 33809 invoked by uid 500); 23 Nov 2016 15:20:07 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 33800 invoked by uid 99); 23 Nov 2016 15:20:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Nov 2016 15:20:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 351B6C033A for ; Wed, 23 Nov 2016 15:20:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.198 X-Spam-Level: X-Spam-Status: No, score=-1.198 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id U-KpP3SCI1nU for ; Wed, 23 Nov 2016 15:20:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 185F15F39A for ; Wed, 23 Nov 2016 15:20:02 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 94CF1E002C for ; Wed, 23 Nov 2016 15:20:01 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 91DE83A036D for ; Wed, 23 Nov 2016 15:20:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1001535 - in /websites/production/tapestry/content: cache/main.pageCache hibernate-user-guide.html integrating-with-jpa.html Date: Wed, 23 Nov 2016 15:20:01 -0000 To: commits@tapestry.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161123152001.91DE83A036D@svn01-us-west.apache.org> archived-at: Wed, 23 Nov 2016 15:20:10 -0000 Author: buildbot Date: Wed Nov 23 15:20:01 2016 New Revision: 1001535 Log: Production update by buildbot for tapestry Modified: websites/production/tapestry/content/cache/main.pageCache websites/production/tapestry/content/hibernate-user-guide.html websites/production/tapestry/content/integrating-with-jpa.html Modified: websites/production/tapestry/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/tapestry/content/hibernate-user-guide.html ============================================================================== --- websites/production/tapestry/content/hibernate-user-guide.html (original) +++ websites/production/tapestry/content/hibernate-user-guide.html Wed Nov 23 15:20:01 2016 @@ -64,16 +64,9 @@
-
- -

Entity value encoding

- -

Value encoders are automatically created for all mapped Hibernate entity types. This is done by encoding the entity as it's id (coerced to a String) and decoding the entity by looking it up in the Hibernate Session using the encoded id. Consider the following example:

- -
-
-public class ViewPerson
+                

This page describes functionality provided by the Tapestry-hibernate-core module, but the descriptions apply equally to the Tapestry-jpa module.

Entity value encoding

The Tapestry-hibernate-core module provides Value Encoder automatically for all mapped Hibernate entity types. This is done by encoding the entity as it's id (coerced to a String) and decoding the entity by looking it up in the Hibernate Session using the encoded id. Consider the following example:

+
public class ViewPerson
 {
   @Property
   private Person person;
@@ -88,41 +81,22 @@ public class ViewPerson
     return person;
   }
 }
-
- -
-
-<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+
+
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
 <body>
   The person's name is: ${person.name}
 </body>
 </html>
-
- -

Accessing the page as /viewperson/152 would load the Person entity with id 152 and use that as the page context.

- -

Using @PageActivationContext

- -

If you prefer to use annotations, you may let Tapestry generate the page activation context handlers for you. Relying on an existing ValueEncoder for the corresponding property you can use the @PageActivationContext annotation. The disadvantage is that you can't access the handlers in a unit test.

- -
-
-public class ViewPerson
+

Accessing the page as /viewperson/152 would load the Person entity with id 152 and use that as the page context.

Using @PageActivationContext

If you prefer to use annotations, you may let Tapestry generate the page activation context handlers for you. Relying on an existing ValueEncoder for the corresponding property you can use the @PageActivationContext annotation. The disadvantage is that you can't access the handlers in a unit test.

+
public class ViewPerson
 {
   @Property
   @PageActivationContext
   private Person person;
   
 }
-
- -

Using @Persist with entities

- -

If you wish to persist an entity in the session, you may use the "entity" persistence strategy:

- -
-
-public class ViewPerson
+

Using @Persist with entities

If you wish to persist an entity in the session, you may use the "entity" persistence strategy:

+
public class ViewPerson
 {
   @Persist("entity")
   @Property
@@ -134,23 +108,12 @@ public class ViewPerson
   }
   
 }
-
- -

This persistence strategy works with any Hibernate entity that is associated with a valid Hibernate Session by persisting only the id of the entity. Notice that no onPassivate() method is needed; when the page renders the entity is loaded by the id stored in the session.

- -

Using @SessionState with entities

- +

This persistence strategy works with any Hibernate entity that is associated with a valid Hibernate Session by persisting only the id of the entity. Notice that no onPassivate() method is needed; when the page renders the entity is loaded by the id stored in the session.

Using @SessionState with entities

- -

Added in 5.2

+

Added in 5.2

-
- -

The default strategy for persisting Session State Objects is "session". Storing a Hibernate entity into a <HttpSession> is problematic because the stored entity is detached from the Hibernate session. Similar to @Persist("entity") you may use the "entity" persistence strategy to persist Hibernate entities as SSOs:

- -
-
-public class Index
+

 

The default strategy for persisting Session State Objects is "session". Storing a Hibernate entity into a <HttpSession> is problematic because the stored entity is detached from the Hibernate session. Similar to @Persist("entity") you may use the "entity" persistence strategy to persist Hibernate entities as SSOs:
+
public class Index
 {
   @SessionState
   @Property
@@ -160,13 +123,8 @@ public class Index
   
 }
 
-
- -

For this purpose you need to set the value of the symbol <HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED> to <true>:

- -
-
-public class AppModule
+

For this purpose you need to set the value of the symbol <HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED> to <true>:

+
public class AppModule
 {
     public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
     {
@@ -174,13 +132,8 @@ public class AppModule
     }
 }
 
-
- -

Alternatively you can apply the "entity" persistence strategy to a single Hibernate entity:

- -
-
-public class AppModule
+

Alternatively you can apply the "entity" persistence strategy to a single Hibernate entity:

+
public class AppModule
 {
     public void contributeApplicationStateManager(MappedConfiguration<Class, ApplicationStateContribution> configuration)
     {
@@ -188,17 +141,8 @@ public class AppModule
     }
 }
 
-
- -

Committing Changes

- -

All Hibernate operations occur in a transaction, but that transaction is aborted at the end of each request; thus any changes you make will be lost unless the transaction is committed.

- -

The correct way to commit the transaction is via the @CommitAfter annotation:

- -
-
-public class EditPerson
+

Committing Changes

All Hibernate operations occur in a transaction, but that transaction is aborted at the end of each request; thus any changes you make will be lost unless the transaction is committed.

The correct way to commit the transaction is via the @CommitAfter annotation:

+
public class EditPerson
 {
   @Persist("entity")
   @Property
@@ -220,31 +164,8 @@ public class EditPerson
     return personIndex;
   }
 }
-
- -

In this example, the Person object may be updated by a form; the form's success event handler method, onSuccess() has the @CommitAfter annotation.

- -

Behind the scenes, the @CommitAfter annotation causes the HibernateSessionManager's commit() method to be executed before the method returns.

- -

The transaction will be committed when the method completes normally.

- -

The transaction will be aborted if the method throws a RuntimeException.

- -

The transaction will be committed if the method throws a checked exception (one listed in the throws clause of the method).

- -

Managing Transactions using DAOs

- -

As your application grows, you will likely create a Data Access Object layer between your pages and the Hibernate APIs.

- -

The @CommitAfter annotation can be useful there as well.

- -

You may use @CommitAfter on method of your service interface, then use a decorator to provide the transaction management logic.

- -

First definine your DAO's service interface:

- -
-
-public interface PersonDAO
+

In this example, the Person object may be updated by a form; the form's success event handler method, onSuccess() has the @CommitAfter annotation.

Behind the scenes, the @CommitAfter annotation causes the HibernateSessionManager's commit() method to be executed before the method returns.

The transaction will be committed when the method completes normally.

The transaction will be aborted if the method throws a RuntimeException.

The transaction will be committed if the method throws a checked exception (one listed in the throws clause of the method).

Managing Transactions using DAOs

As your application grows, you will likely create a Data Access Object layer between your pages and the Hibernate APIs.

The @CommitAfter annotation can be useful there as well.

You may use @CommitAfter on method of your service interface, then use a decorator to provide the transaction management logic.

First definine your DAO's service interface:

+
public interface PersonDAO
 {
   Person findByName(String name);
 
@@ -257,35 +178,21 @@ public interface PersonDAO
   @CommitAfter
   void delete(Person person);
 }
-
- -

Next, define your service in your application's Module class:

- -
-
-public class AppModule
+

Next, define your service in your application's Module class:

+
public class AppModule
 {
    public static void bind(ServiceBinder binder)
    {
       binder.bind(PersonDAO.class, PersonDAOImpl.class);
    }
 }
-
- -

Finally, you should use the HibernateTransactionAdvisor to add transaction advice:

- -
-
-    @Match("*DAO")
+

Finally, you should use the HibernateTransactionAdvisor to add transaction advice:

+
    @Match("*DAO")
     public static void adviseTransactions(HibernateTransactionAdvisor advisor, MethodAdviceReceiver receiver)
     {
         advisor.addTransactionCommitAdvice(receiver);
     }
-
- -

This advice method is configured to match against any service whose id ends with "DAO", such as "PersonDAO".

- -

The advisor scans the service interface and identifies any methods with the @CommitAfter annotation.

+

This advice method is configured to match against any service whose id ends with "DAO", such as "PersonDAO".

The advisor scans the service interface and identifies any methods with the @CommitAfter annotation.

Modified: websites/production/tapestry/content/integrating-with-jpa.html ============================================================================== --- websites/production/tapestry/content/integrating-with-jpa.html (original) +++ websites/production/tapestry/content/integrating-with-jpa.html Wed Nov 23 15:20:01 2016 @@ -67,19 +67,19 @@

Added in 5.3

-

 

Starting with Tapestry 5.3, Tapestry provides built-in integration with the Java Persistence API (JPA) through the Tapestry-jpa module. This module supersedes the Tynamo JPA module.

Contents

+/*]]>*/

Downloading

The Tapestry-jpa module is not automatically included in Tapestry applications because of the additional dependencies it requires. If you're using Maven, just add the tapestry-jpa dependency to your application's pom.xml file, something like this:

pom.xml (partial)
<dependency>
     <groupId>org.apache.tapestry</groupId>
@@ -167,7 +167,7 @@ div.rbtoc1479910788609 li {margin-left:
       configuration.add("com.acme.model");
    }
 }
-

As you can see, you may add as many packages as you wish.

Configuration Settings

The following can be configured in your application module (usually AppModule.java), just like other Tapestry configuration symbols.

SymbolDefaultDescription
JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERStrue 
JpaSymbols.EARLY_START_UPtrue 60;
JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLEDtrue 
JpaSymbols.PERSISTENCE_DESCRIPTOR/META-INF/persistence.xml 

 

Injecting the EntityManager

The created entity managers can be injected into page, component and other services.

Injecting the EntityManager into page and component classes

Depending on whether more than one persistence unit has been defined, the way to inject EntityManager varies slightly. Let’s start with a simple scenario, where only a single persistence unit is defined. In this case, an EntityManager can be injected using the @PersistenceContext annotation.

CreateAddress.java
+

As you can see, you may add as many packages as you wish.

Configuration Settings

Several aspects of Tapestry-jpa can be customized in your application module (usually AppModule.java), just like other Tapestry configuration symbols.

SymbolDefaultDescription
JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERStrueWhether entity value encoders will be provided automatically. See Using Select with a List.
JpaSymbols.EARLY_START_UPtrueWhether JPA will be started up at application launch, rather than lazily.
JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLEDtrue

Whether the "entity" persistence strategy is used to store JPA entities as Session State Objects.

JpaSymbols.PERSISTENCE_DESCRIPTOR/META-INF/persistence.xmlThe location of the persistence configuration file, located on the classpath

Injecting the EntityManager

The created entity managers can be injected into page, component and other services.

Injecting the EntityManager into page and component classes

Depending on whether more than one persistence unit has been defined, the way to inject EntityManager varies slightly. Let’s start with a simple scenario, where only a single persistence unit is defined. In this case, an EntityManager can be injected using the @PersistenceContext annotation.

CreateAddress.java
public class CreateAddress {
 
    @PersistenceContext
@@ -181,7 +181,7 @@ div.rbtoc1479910788609 li {margin-left:
       entityManager.persist(address);
    }
 }
-

Alternatively, you can use the @Inject annotation to get the EntityManager injected into a page or component, as shown in the following example.

CreateAddress.java
+

Alternatively, you can use the @Inject annotation to get the EntityManager injected into a page or component, as shown in the following example.

CreateAddress.java
public class CreateAddress {
 
    @Inject
@@ -236,7 +236,7 @@ div.rbtoc1479910788609 li {margin-left:
 
    ...
 }
-

Transaction management

As you may already know from the Hibernate integration library, Tapestry automatically manages transactions for you. The JPA integration library defines the @CommitAfter annotation, which acts as the correspondent annotation from the Hibernate integration library. Let’s explore the UserDao interface to see the annotation in action.

UserDao.java
+

Value Encoders

The Tapestry-jpa module automatically provides value encoders to make it easy to work with entities (especially lists of entities) in your Tapestry pages and components. This is modeled on the similar functionality from the Tapestry-hibernate-core module. See the Hibernate User Guide for all the details.

Transaction Management

As you may already know from the Hibernate integration library, Tapestry automatically manages transactions for you. The JPA integration library defines the @CommitAfter annotation, which acts as the correspondent annotation from the Hibernate integration library. Let’s explore the UserDao interface to see the annotation in action.

< b>UserDao.java
public interface UserDao {
 
    @CommitAfter