2007 JavaOne SM Conference | Session BOF-4181 | BOF-4181 Migrating a Spring/Hibernate Application to Java Platform, Enterprise Edition (Java EE) 5 Adrian.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Copyright ©2010 Oracle Corporation Made available under Creative Commons Attribution-Share Alike 3.0 Unported EclipseLink Runtime Architecture Data Source.
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
Spring, Hibernate and Web Services 13 th September 2014.
.NET Database Technologies: Open-Source Frameworks.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
© Internna Technologies 1 IWebMvc Features, Possibilities & Goals.
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Using Third-Party Frameworks in Building Blocks™ David Ashman Principal Architect, Product Development.
An Introduction to Hibernate Matt Secoske
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Object Persistence and Object-Relational Mapping James Brucker.
CIS 764 Kansas State University
Introduction to JPA Java Persistence API Introduction to JPA.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
Rice KRAD Data Layer JPA Design Eric Westfall July 2013.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
NetArchive Suite Workshop 2011 Technical Track - Code refactoring with the Spring Framework.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Agenda What is Hibernate Spring Integration Questions Overview
Maven for building Java applications By Nalin De Zoysa
JPA Java Persistence API. Introduction The Java Persistence API provides an object/relational mapping facility for managing relational data in Java applications.
Object persistence with Hibernate in Decision Deck 1.1 Gilles Dodinet 2 nd Decision Deck Workshop 2008, February.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Dali JPA Tools. About Dali Dali JPA Tools is an Eclipse Web Tools Platform sub-Project Dali 1.0 is a part of WTP 2.0 Europa coordinated release Goal -
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Topic : JPA Kaster Nurmukan. Overview of JPA EntityManager.
Introduction to Web Dimitar Nenchev Ivan Nakov
Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.
1 Apache TomEE // JavaEE Web Profile on Tomcat Jonathan #TomEE.
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Topic : Hibernate 2: Object Persistence and ORM Kaster Nurmukan.
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
Ganymede Simultaneous Release | © 2008 by Springsite B.V., The Netherlands made available under the EPL v1.0 Teneo Ganymede Simultaneous Release.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Fall CIS 764 Database Systems Engineering L18.2 : Object Relational Mapping … ….Object persistence.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Java Persistence API part 1 INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
v110912Java Persistence: EntityManager2 Overview Earlier versions of EJB Specification defined the persistence layer –javax.ejb.EntityBean Java EE 5 moved.
By Srinivas Mahakud Java Persistence API JPA. Review Topics: Introduction what is the JPA? What is the JPA contains of? Why developers should Create the.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Fundamentals of MyBATIS
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
IS-907 Java EE Introduction to JPA. Java Persistence API A framework for using relational databases in Java programs mapping between tables and classes,
.  A reference model developed for an important use case (Air Job) including UI widgets, controllers, services and DAOs.  After full requirement analysis.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Fall CIS 764 Database Systems Engineering L11: Object Relational Mapping … (a) ORM, Object persistence (b) Pets sequence.
CS520 Web Programming Spring – Inversion of Control Chengyu Sun California State University, Los Angeles.
The Holmes Platform and Applications
Chengyu Sun California State University, Los Angeles
J2EE Lecture 6: Spring – IoC and Dependency Injection
CS520 Web Programming Spring – Inversion of Control
Advanced Java Programming
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Developing and testing enterprise Java applications
Teneo Ganymede Mini Deck
Chengyu Sun California State University, Los Angeles
Presentation transcript:

2007 JavaOne SM Conference | Session BOF-4181 | BOF-4181 Migrating a Spring/Hibernate Application to Java Platform, Enterprise Edition (Java EE) 5 Adrian Görler & Robin de Silva Jayasinghe SAP AG YOUR LOGO HERE

2007 JavaOne SM Conference | Session BOF-4181 | 2 Goal of our BOF-Session Learn about possible migration paths from Spring/Hibernate to Java EE 5

2007 JavaOne SM Conference | Session BOF-4181 | 3 Agenda Introduction Hibernate vs. JPA Migrating Persistence Spring Beans vs. EJB 3 Migrating Business Logic

2007 JavaOne SM Conference | Session BOF-4181 | 4 J2EE 1.4 Widely adopted standard environment for Enterprise Java Many implementations by different vendors But: Complex to use & implement Heavy-weight persistence model (EJB CMP) Invasive Boilerplate coding

2007 JavaOne SM Conference | Session BOF-4181 | 5 Rise of Spring and Hibernate Spring Application framework Dependency Injection AOP support Non-invasiveness as a basic principle O/R persistence support for various frameworks Hibernate POJO based O/R persistence Spring and Hibernate have become a popular alternative to J2EE development.

2007 JavaOne SM Conference | Session BOF-4181 | 6 Java EE 5 Major goal: Ease of development Adopted patterns from the community: POJO based persistence (JPA 1.0) IoC (Resource Injection) Limited AOP capability (EJB Interceptors) Reduced configuration effort by enhanced defaulting. Emphasizes on configuration via annotations XML still possible

2007 JavaOne SM Conference | Session BOF-4181 | 7 Motivation for a Migration Acceptance of Java EE 5 in the community Support of Java EE 5 by major platform vendors Fully exploit the features of your Java EE 5 server Adopt the new JPA standard Have a portable persistence layer Independence off 3rd party libraries

2007 JavaOne SM Conference | Session BOF-4181 | 8 Agenda Introduction Hibernate vs. JPA Migrating Persistence Spring Beans vs. EJB 3 Migration Business Logic

2007 JavaOne SM Conference | Session BOF-4181 | 9 Hibernate vs. Java Persistence API JPA 1.0 Part of Java EE 5 Basic but complete persistence solution Integrates very smoothly with EJB 3 Pluggable persistence provider Hibernate 3 Open source Very capable, solid and mature

2007 JavaOne SM Conference | Session BOF-4181 | 10 Roots of Java Persistence API Features and Restrictions Hibernate JDO Toplink JPA

2007 JavaOne SM Conference | Session BOF-4181 | 11 Hibernate vs. JPA: Mapping Java Persistence API standardized object-relational mapping common ground (incl. relationships, inheritance,...) annotations or XML (orm.xml) Hibernate XML (*.hbm.xml) very powerful and flexible Hibernate Annotations bridge between Hibernate and JPA makes Hibernate understand JPA annotations Hibernate-specific extensions

2007 JavaOne SM Conference | Session BOF-4181 | 12 Hibernate vs. JPA: API persist getReference refresh find no equivalent no equivalent merge save load(Class, id) load (Object, id) get saveOrUpdate/update evict merge JPAHibernate

2007 JavaOne SM Conference | Session BOF-4181 | 13 Hibernate vs. JPA: Queries Common Features very similar SQL-like query languages Named, dynamic and native (SQL) queries Java Persistence Query Language (JPQL) Less prone to portability issues Hibernate Query Language (HQL) Fully exploits database Bridge: Hibernate understands both HQL and JPQL Hibernate beyond JPA: API Query.iterate, Scrollable iteration, Criteria,...

2007 JavaOne SM Conference | Session BOF-4181 | 14 Hibernate to JPA: Migration Options JPA with default Persistence Provider Hardly any Hibernate-specific Mapping Uses only a subset of the API covered by JPA JPA with Hibernate EM as Persistence Provider Hibernate-specific Mapping Uses only a subset of the API covered by JPA partly sacrifices standard-adoption depends on different third-party libs

2007 JavaOne SM Conference | Session BOF-4181 | 15 Agenda Introduction Hibernate vs. JPA Migrating Persistence Spring Beans vs. EJB 3 Migrating Business Logic

2007 JavaOne SM Conference | Session BOF-4181 | 16 Persistent Classes DB UI Spring Local Session FactoryBean Tx Hibernate TxManager Spring Beans Business Layer DAO Layer HibernateSession *.hmb.xml Spring Hibernate Java EE Initial Application

2007 JavaOne SM Conference | Session BOF-4181 | 17 Migration Step 1: Mapping: Hibernate/Annotations Mapping: Hibernate -> JPA Hibernate XML -> JPA Annotations Data Access API: Hibernate Resources/Transactions : Spring Integration Technology: Spring

2007 JavaOne SM Conference | Session BOF-4181 | 18 Hibernate/Annotations - Convert the model to JPA Evaluate applicability: Can mappings be expressed using JPA annotations? Declare mapping of entities using JPA public class Customer int id; String name; } Remove *.hbm.xml files

2007 JavaOne SM Conference | Session BOF-4181 | 19 Hibernate/Annotations - Configure SessionFactory for Annotations application context xml: com.sap...Organization... com.sap.efs.model...

2007 JavaOne SM Conference | Session BOF-4181 | 20 Entities DB UI Spring Annotations Session FactoryBean Tx Hibernate TxManager Spring Beans Business Layer DAO Layer HibernateSession JPA Annotations Spring Hibernate Java EE Hibernate Annotations

2007 JavaOne SM Conference | Session BOF-4181 | 21 Migration Step 2: Data Access Layer: Spring/JPA Mapping: JPA Data Access API: Hibernate -> JPA SessionFactory -> EntityManagerFactory HibernateTransactionManager -> JpaTransactionManager HibernateTemplate -> JPA Resources/Transactions : Spring Integration Technology: Spring

2007 JavaOne SM Conference | Session BOF-4181 | 22 Spring/JPA - Convert the DAO Layer to JPA Evaluate applicability: Can Hibernate API be replaced by JPA? Use JPA annotations in your business (unitName="EFSApplication") EntityManager em;... Customer findCustomer(int id) { return em.find(Customer.class, id) }

2007 JavaOne SM Conference | Session BOF-4181 | 23 Spring/JPA - Declare the Persistence Unit persistence.xml:

2007 JavaOne SM Conference | Session BOF-4181 | 24 Spring/JPA - Configuration Options LocalEntityManagerFactoryBean Application perspective EMF created using javax.persistence.Persistence little control LocalContainerEntityManagerFactoryBean JPA Container Perspective EMF created using javax.persistence.spi.PersistenceProvider full control EntityMangerFactory or EntityManager from JNDI

2007 JavaOne SM Conference | Session BOF-4181 | 25 Spring/JPA - Configure Spring for JPA...

2007 JavaOne SM Conference | Session BOF-4181 | 26 Entities DB UI Spring EntityManager FactoryBean Tx Jpa TxManager Spring Beans Business Layer DAO Layer EntityManager JPA Annotations Spring Hibernate Java EE Spring & JPA

2007 JavaOne SM Conference | Session BOF-4181 | 27 Migration Step 3: Resources/Transactions Mapping: JPA Data Access API: JPA Resources/Transactions: Java EE/JTA Resource Creation: Spring -> Java EE Resource Management: Spring -> Java EE Transactions: Local -> JTA Integration Technology: Spring

2007 JavaOne SM Conference | Session BOF-4181 | 28 Spring/JPA – Bind/Lookup EntityManager in JNDI web.xml: em/EFS EFSApplication application context xml:

2007 JavaOne SM Conference | Session BOF-4181 | 29 Spring/JPA - Switch Transaction Type to JTA persistence.xml:... application context xml: TransactionManager

2007 JavaOne SM Conference | Session BOF-4181 | 30 Entities DB UI Spring Tx Spring Beans Business Layer DAO Layer JPA Annotations Java EE JNDI JTA EJB3 JPA Container EntityManager JPA PostProcessor Jta TxManager Spring Hibernate Java EE Backed by Java EE

2007 JavaOne SM Conference | Session BOF-4181 | 31 Agenda Introduction Hibernate vs. JPA Migrating Persistence Spring Beans vs. EJB 3 Migrating Business Logic

2007 JavaOne SM Conference | Session BOF-4181 | 32 Spring vs. EJB 3 Evaluate if migration-step is evaluable. Following areas have to be analyzed: Declarative transactions Aspect-oriented Programming (AOP) Inversion of Control (IoC) If all is applicable: Remove the middleman! ;-)

2007 JavaOne SM Conference | Session BOF-4181 | 33 AOP Support EJB 3 Interceptors Pointcut declaration with interceptor-binding Per class/method and default interceptors One Joinpoint definition Spring AOP Flexible pointcut-expression language Joinpoint-types

2007 JavaOne SM Conference | Session BOF-4181 | 34 Declarative Transactions EJB 3.0 CMT JTA Global transactions only Spring transactions-management-framework Pluggable transaction-managers Global & local transactions

2007 JavaOne SM Conference | Session BOF-4181 | 35 Inversion of Control EJB 3 Resource Injection Defined injectable types and targets Configuration via annotations (and XML) Spring IoC Fully configurable Dependency Injection Configuration is done via XML-configuartion

2007 JavaOne SM Conference | Session BOF-4181 | 36 Agenda Introduction Hibernate vs. JPA Migrating Persistence Spring Beans vs. EJB 3 Migrating Business Logic

2007 JavaOne SM Conference | Session BOF-4181 | 37 Migration Step 4: Business Layer Mapping: JPA Data Access API: JPA Resources/Transactions: Java EE/JTA Integration Technology: EJB 3 pure Web Application -> EAR Spring Beans -> EJB 3 Session Beans

2007 JavaOne SM Conference | Session BOF-4181 | 38 Spring Beans to EJB Session Beans Prerequisites Prerequisite Java EE 5 compatible dependencies only Beans don‘t depend on any Spring API JPA-DAOs should use plain JPA Beans without Spring dependecies can be directly used as EJB 3 sessionbeans. Spring transaction-declaration has to be migrated to EJBs

2007 JavaOne SM Conference | Session BOF-4181 | 39 Spring Beans to EJB Session Beans Repackaging Web Services Data access Entities (JPA) web archive ejb archive Web Services Data access Entities (JPA) ear archive Libraries

2007 JavaOne SM Conference | Session BOF-4181 | 40 Entities DB UI Java EE JPA Tx JTA EJB3 Business Layer DAO Layer EntityManager JPA Annotations Spring Hibernate Java EE Migration Result

2007 JavaOne SM Conference | Session BOF-4181 | 41 Conclusion Spring/Hibernate and Java EE 5 address same issues and have many commonalities. An application can be migrated in a controlled fashion with fully functional intermediate steps. Most work is done by adapting configuration and refactoring the data access layer. Give it a try!

2007 JavaOne SM Conference | Session BOF-4181 | 42 For More Information Other sessions at JavaOne TS Java Persistence API: Best Practices and Tips TS Java Persistence API: Portability Do’s and Don’ts TS Implementing Java EE Applications, Using Enterprise JavaBeans (EJB) 3 Technology: Real-World Tips, Tricks, and New Design Patterns TS Harnessing the Power of Java Platform, Enterprise Edition (Java EE) Technology With Spring TS Java Persistence 2.0 Pro EJB 3: Java Persistence API Java Persistence Migration Guide Java Persistence with Hibernate

2007 JavaOne SM Conference | Session BOF-4181 | 43 Q&A

2007 JavaOne SM Conference | Session BOF-4181 | 44 Spring JPA managed by Spring LocalContainerEMFBean Spring Hibernate Java EE LocalContainer EMFBean JPA Persistence- Provider applicationContext.xml (Spring-Config) applicationContext.xml (Spring-Config) persistence.xml (JPA-Config) persistence.xml (JPA-Config) JPA EMF

2007 JavaOne SM Conference | Session BOF-4181 | 45 Hibernate beyond JPA: Tuning Different Fetching Strategies Custom SQL Second Level Caches

2007 JavaOne SM Conference | Session BOF-4181 | 46 JPA managed by Java EE 5 Server JPA Persistence- Provider JPA Persistence- Provider JNDI Spring Beans Spring Hibernate Java EE JPA EM/EMF Java EE 5 Spring

2007 JavaOne SM Conference | Session BOF-4181 | 47 Spring JPA managed by Spring LocalEMFBean LocalEntiyManager FactoryBean JPA Persistence- Provider JPA EMF applicationContext.xml (Spring-Config) applicationContext.xml (Spring-Config) persistence.xml (JPA-Config) persistence.xml (JPA-Config) Spring Hibernate Java EE javax.persistence. Persistence

2007 JavaOne SM Conference | Session BOF-4181 | 48 Hibernate vs. JPA: Mapping (II) JPA-incompatible Mappings in Hibernate Custom value types More id Generators Collections of values Indexed collections (lists, arrays) Association mapping more flexible Nested components...