Integrating Spring, JPA, Apache wicket into Google Application Engi


2009-12-04 22:34 | Author: vytautas.racelis

@Deprecated

There are many examples how to create simple Wicket applications for Google application engine without Spring, JPA support. I would like to share how to create fully working application with JPA, Spring, Spring Transactions and Apache Wicket.

Once again, i guess you already know how to create simple Wicket application fot Google app engine. If not, you may read this article first.

Preparing dependencies

Jar dependencies

- Apache wicket 1.4-rc4
- sl4j
- Spring 3.0.0.M3
- commons-logging
- antlr 3.0.1
- asm 2.2.3
- cglib nodep 2.1.3
- aopalliance 1.0

Maven dependencies

If you are using maven style, you might use this snippet to get maven dependencies of 3th party libraries. They are provided at the end this article :)

These dependencies do not include Google app engine dependencies, because these should be installed by yourself.

Updating web.xml

In order to use spring, you must register spring listener in web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:META-INF/application-context.xml,
classpath*:META-INF/infrastructure-context.xml,
classpath*:META-INF/entitymanager.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Creating persistence.xml

The file persistence.xml exists to define the various persistence-units that are to be available for persistence using JPA. Each persistence-unit defines a set of classes and their mapping characteristics when persisting them. So you must define datanucleus provider:

<persistence-unit name="xaloon">
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true" />
<property name="datanucleus.NontransactionalWrite" value="true" />
<property name="datanucleus.ConnectionURL" value="appengine" />
</properties>
</persistence-unit>

Preparing transaction management and entity manager

Usually we use org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean as a bean for entity manager factory, but i could not make it working, so there is another bean provided by spring: org.springframework.orm.jpa.LocalEntityManagerFactoryBean

<bean id="entityManagerFactory" 
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" lazy-init="true">
<property name="persistenceUnitName" value="xaloon" />
</bean>
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven />

Writing simple Create/delete sample

WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId
(true);
    add
(container);
    DataView<Customer> view =
new DataView<Customer>("view", new CustomerProvider(), 5) {
   
     
/**
       *
       */
     
private static final long serialVersionUID = 1L;

     
@Override
     
protected void populateItem(Item<Customer> arg0) {
       
updateItem (arg0, arg0.getModelObject());
     
}
    }
;
    container.add
(view);
    container.add
(new AjaxPagingNavigator("navigator", view));

Final result

Final application might be found here

Source code might be found here

No issues?

Well, seems that i have to wait for at least 6 months in order to use google application engine fully.

1. I tried to use order by id in search criteria. Development environment was fine, but production - nope. Did follow this thread, but no result.

Also there is another issue related to automatic index generation. There is a bug in current app engine SDK

2. "select from" needs whole package and entity name used in search query.


Maven dependencies
<properties>
<spring.version>3.0.0.M2</spring.version>
<wicket.version>1.4-rc4</wicket.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.transaction</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web.servlet</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
</dependency>
<!-- WICKET -->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-auth-roles</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>${wicket.version}</version>
</dependency>
<!-- WICKET STUFF -->
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>annotation</artifactId>
<version>1.4-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.3</version>
</dependency>
</dependencies>

 
 
 
 
 
 
 
<< < > >>
 
About xaloon.org

xaloon.org provides apache wicket based components for web and business solutions.

Learn more »
Follow Us (RSS)
Help & Support

Contact us in order to get help and support.

Online contact form »
Get in touch
Online contact form »