Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Examples/JPA/Spring Web Tutorial
< EclipseLink | Examples | JPA
Contents
- 1 EclipseLink JPA Deployed on Spring
- 1.1 Purpose
- 1.2 JPA Enterprise Application running on Spring inside WebLogic Server
- 1.3 JEE and Spring correspondence
- 1.4 Architecture
- 1.5 Installation
- 1.6 Create Enterprise Projects
- 1.7 Object Model
- 1.8 Dependency Injection
- 1.9 Web.xml
- 1.10 org.eclipse.persistence.jpa.PersistenceProvider
- 1.11 Persistence.xml
- 1.12 servlet-config.xml
- 1.13 application-config.xml
- 1.14 Transaction Manager Configuration
- 1.15 Servlet Client
- 1.16 Start Server
- 1.17 Publish EAR
- 1.18 Console Output
- 1.19 Browser Output
- 1.20 Downloading EclipseLink Libraries
- 1.21 Eclipse Launch Targets
- 1.22 Change Log
- 1.23 References
- 1.24 Known Issues
EclipseLink JPA Deployed on Spring
This content is undergoing an expansion as of 20101220 in enhancement # 332953
Purpose
- The open source persistence provider - EclipseLink JPA or native EclipseLink can be the JPA or ORM provider for Spring beans in Spring based applications.
- The API provided by the Spring framework can range from using the dependency injection (DI) features along with the Aspect Oriented Programming (AOP) support - all the way to using declarative transactions and management of remote resources.
- In this tutorial page we will concentrate on providing support for developers and projects that wish to use EclipseLink with Spring applications and we will demonstrate a very simple web application that uses either a JTA or local RESOURCE_LOCAL persistence unit and use Spring's @Autowired, @Controller, @RequestMapping, @Repository and possibly the AOP @Aspect and @Around annotations as required.
JPA Enterprise Application running on Spring inside WebLogic Server
- The primary use case we will prototype for this tutorial is one where the application uses Spring (either managing its' own local transactions, or using the transaction manager in WebLogic for distributed transactions) as the enterprise container on WebLogic Server. WebLogic currently support Spring 2.5.3 and Dependency Injection using Spring in non-Spring applications via the open source Pitchfork project.
- Therefore theoretically we should be able to use Spring AOP and other DI annotations in our application without any extra configuration - we will verify this.
- A secondary use case will be migration of a SpringSource Tool Suite 2.5.0.M3 (based on Eclipse 3.6 and Apache Tomcat 6.0.20) based native Hibernate project to one that uses EclipseLink JPA.
JEE and Spring correspondence
- Spring can be used in parallel with formal EE specification technologies like IIOP Remote Session Beans and Transactions or as an alternative to them using Spring's remote RMI/JAX-RPC/WS proxying and declarative transactions/rollback support.
- However, Spring does not provide native distributed transaction support or native ORM support - in both these cases JEE must be used.
- Distributed transactions via transactions that occur across remote session bean methods
- ORM persistence is provided via JPA (using either EclipseLink or Hibernate as the provider) - or via native ORM for either of these persistence providers.
- Using the Spring framework as the EE container allows the user to run enterprise applications on simple JSR-154 Servlet containers like Tomcat, Jetty, WebSphere CE, Spring TC or Spring DM/Virgo
- The spring framework treats all EE artificts as Spring Beans
Architecture
- There are 3 standard tiers to our web application.
- 1) presentation/view layer (JSP/JSF pages)
- 2) controller layer (Controller Servlet)
- 3) integration/data-access layer (Spring beans)
- The cross-cutting concerns are
- 1) The data model (Entities)
- 2) Logging
- 3) Transaction Management (Spring beans)
- We will be using standard JPA Entities for our data model domain objects.
- The domain objects will be managed by Spring beans that act as Data Access Objects between our Entities and the persistence store
Installation
WebLogic 10.3.3.0
- In WebLogic 10.3.3.0 there exists 3 spring jars in the modules directory - these are internally wrapped API that support the 2.5.3 version of Spring as indicated. We may upgrade these to work with Spring 3 as long as we do not encounter issues between 2.5.3 and 3.0 dependency injection. The pitchfork jar is part of the Oracle open source project for metadata translation of JSR-250 annotations.
- com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_2-0.jar
- com.bea.core.repackaged.springframework.spring_1.1.0.0_2-5-3.jar
- com.bea.core.weblogic.spring.instrument_1.2.0.0.jar
- The notable thing about using the com.bea.core namespace is that it will not confict with any com.springsource Spring versions shipped with Spring EAR applications.
Eclipse 3.6 Setup
Standard Eclipse 3.6 EE
- Spring must be configured as follows.
SpringSource Tools Suite 2.5.1
- Spring will run out of the box on Apache Tomcat 6.0.20
JNDI Datasource Setup
EclipseLink JAR
Spring JARs
Create Enterprise Projects
- Possible configurations of the projects are...
- SC1: WAR only project with entities/beans inside war jar.
- SC2: WAR only project with entities/beans inside separate domain jar.
- SC3: EE EAR project with entities/beans inside the war project
- SC4: EE EAR project with entities/beans inside separate ejb.jar project
- SC5: EE EAR project with entities/beans inside separate domain jar project
Object Model
- Following Scenario SC3 we will place our entities inside
Dependency Injection
Web.xml
- The version of the xmlns:web namespace must be 2.5 not 2.4
- Add a persistence-ref for this application managed persistence unit
<persistence-context-ref> <persistence-context-ref-name>persistence/em</persistence-context-ref-name> <persistence-unit-name>spring</persistence-unit-name> </persistence-context-ref>
org.eclipse.persistence.jpa.PersistenceProvider
- The SPI file javax.persistence.spi.PersistenceProvider' containing the text org.eclipse.persistence.jpa.PersistenceProvider must be placed at the root of where the entities/beans are off of META-INF/services
Persistence.xml
servlet-config.xml
application-config.xml
- If you were using a Hibernate SessionFactory for ORM you could describe your entities in the AnnotationSessionFactoryBean bean element to match the class elements from persistence.xml - if auto-discovery was not enabled
- The
Transaction Manager Configuration
Servlet Client
Start Server
Publish EAR
Console Output
Browser Output
Previous 2008 content - currently undergoing refactoring on 20101220
Downloading EclipseLink Libraries
Download EclipseLink using HTTP - recommended
- Proceed to the following URL and download the latest eclipselink.zip which contains everything you need.
- http://www.eclipse.org/eclipselink/downloads/index.php
- Click on the "EclipseLink 1.0.2 Installer Zip link which resolves to http://www.eclipse.org/downloads/download.php?file=/rt/eclipselink/releases/1.0.2/eclipselink-1.0.2.zip
- http://www.eclipse.org/eclipselink/downloads/index.php
- Expand the zip file and get the following 2 files
- eclipselink-1.0.2\eclipselink\jlib\eclipselink.jar
- eclipselink-1.0.2\eclipselink\jlib\jpa\javax.persistence_1.0.0.jar
Download EclipseLink using Maven
See the repository on http://www.eclipse.org/eclipselink/downloads/index.php
Download EclipseLink using SVN - developers only
- Get the following eclipselink.jar and javax.persistence*.jar from http://www.eclipselink.org ready for your EclipseLink shared library - (I am running rev 2.0.0.20090218-SNAPSHOT)
- The following page details four different ways to either obtain the binary jars or download the source and build them yourself with an anon account.
- http://wiki.eclipse.org/EclipseLink/Source
http://www.springframework.org/download
http://sourceforge.net/project/downloading.php?group_id=73357&use_mirror=voxel&filename=spring-framework-2.5.5-with-dependencies.zip&50273885
Eclipse Launch Targets
-javaagent:c:\opt\spring3\org.springframework.instrument-3.0.0.RELEASE.jar
Change Log
- 20080922 - start tutorial template (no content)
- 20101217 - revisit tutorial using Spring 3, SpringSource Tool Suite 2.5.0, AspectJ 1.6 weaver at 3019.
References
- Oracle Pitchfork open source metadata translation project
- WebLogic support for Spring Dependency Injection
- 308477
- 332336
- Spring AOP on WebLogic
- User request