Enterprise Java Development using JPA, Hibernate and Spring. Srini Penchikala Detroit JUG Developer Day Conference November 14, 2009

Similar documents
REST WEB SERVICES IN JAVA EE 6 AND SPRING 3. Srini Penchikala Austin Java User Group March 30, 2010

Java EE 7: Back-End Server Application Development

Fast Track to Spring 3 and Spring MVC / Web Flow

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

Introduction to Spring Framework: Hibernate, Web MVC & REST

Desarrollo de Aplicaciones Web Empresariales con Spring 4

APPLICATION SECURITY ENHANCEMENTS IN JAVA EE 6

Introduction to Spring Framework: Hibernate, Spring MVC & REST

Introduction to Spring 5, Spring MVC and Spring REST

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Spring Framework 2.5: New and Notable. Ben Alex, Principal Software Engineer, SpringSource

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

1 Software Architecture

Application Architectures, Design Patterns

Migrating traditional Java EE applications to mobile

CO Java EE 7: Back-End Server Application Development

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

JVA-117A. Spring-MVC Web Applications

Eclipse Java Ejb 3.0 Tutorial For Beginners With Examples Pdf

POJOs to the rescue. Easier and faster development with POJOs and lightweight frameworks

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

CONFIGURING A SPRING DEVELOPMENT ENVIRONMENT

Seam 3. Pete Muir JBoss, a Division of Red Hat

2005, Cornell University

ADVANCED JAVA TRAINING IN BANGALORE

com Spring + Spring-MVC + Spring-Boot + Design Pattern + XML + JMS Hibernate + Struts + Web Services = 8000/-

Struts: Struts 1.x. Introduction. Enterprise Application

Specialized - Mastering Spring 4.2

Fast Track to EJB 3.0 and the JPA Using JBoss

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

Component based Development. Table of Contents. Notes. Notes. Notes. Web Application Development. Zsolt Tóth

Developing Applications with Java EE 6 on WebLogic Server 12c

1 Markus Eisele, Insurance - Strategic IT-Architecture

Web Application Development Using Spring, Hibernate and JPA

Web Application Development Using Spring, Hibernate and JPA

Spring Interview Questions

Improve and Expand JavaServer Faces Technology with JBoss Seam

Course Content for Java J2EE

JVA-163. Enterprise JavaBeans

Spring Persistence. with Hibernate PAUL TEPPER FISHER BRIAN D. MURPHY

Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Java J Course Outline

Web Application Development Using Spring, Hibernate and JPA

Spring Framework 2.0 New Persistence Features. Thomas Risberg

purequery Deep Dive Part 2: Data Access Development Dan Galvin Galvin Consulting, Inc.

Java EE 6: Develop Business Components with JMS & EJBs

Java Training Center, Noida - Java Expert Program

Spring 2.5 on the Way to 3.0

Design patterns using Spring and Guice

OSGi on the Server. Martin Lippert (it-agile GmbH)

The Next Generation. Prabhat Jha Principal Engineer

Sitesbay.com. A Perfect Place for All Tutorials Resources. Java Projects C C++ DS Interview Questions JavaScript

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

Oracle 10g: Build J2EE Applications

RobertaLab: Configuration, Architecture, Frameworks, Design

Business Logic and Spring Framework

THIS IS ONLY SAMPLE RESUME - DO NOT COPY AND PASTE INTO YOUR RESUME. WE ARE NOT RESPONSIBLE Name: xxxxxx

Call: Core&Advanced Java Springframeworks Course Content:35-40hours Course Outline

CMP 436/774. Introduction to Java Enterprise Edition. Java Enterprise Edition

JVA-117E. Developing RESTful Services with Spring

A domain model-centric approach to J2EE development. Keiron McCammon CTO Versant Corporation

Enterprise JavaBeans, Version 3 (EJB3) Programming

Oracle Developer Day

The Evolution of Java Persistence

Oracle Corporation

Creating RESTful web services with Spring Boot

CORE JAVA. Saying Hello to Java: A primer on Java Programming language

TopLink Grid: Scaling JPA applications with Coherence

SUN Sun Certified Enterprise Architect for J2EE 5. Download Full Version :

Skyway Builder 6.3 Reference

Page 1

JBPM Course Content. Module-1 JBPM overview, Drools overview

1Z Oracle. Java Enterprise Edition 5 Enterprise Architect Certified Master

Comparative Analysis of EJB3 and Spring Framework

Java Advance Frameworks

/ / JAVA TRAINING

IBM WebSphere Application Server 8. Java EE 6 Feature Packs

ECLIPSE PERSISTENCE PLATFORM (ECLIPSELINK) FAQ

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

object/relational persistence What is persistence? 5

~ Ian Hunneybell: CBSD Revision Notes (07/06/2006) ~

Spring MVC. PA 165, Lecture 8. Martin Kuba

Outline. Project Goal. Overview of J2EE. J2EE Architecture. J2EE Container. San H. Aung 26 September, 2003

New Features in Java language

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

Devoxx 2008 in a breeze

CO Java EE 6: Develop Database Applications with JPA

Implementing a Web Service p. 110 Implementing a Web Service Client p. 114 Summary p. 117 Introduction to Entity Beans p. 119 Persistence Concepts p.

Java EE 7 is ready What to do next? Peter Doschkinow Senior Java Architect

SPRING MOCK TEST SPRING MOCK TEST I

Seam. Pete Muir JBoss, a Division of Red Hat.

Spring, a J2EE extension framework. JUGS presentation by Philipp H. Oser

How To Get Database Schema In Java Using >>>CLICK HERE<<<

JavaEE.Next(): Java EE 7, 8, and Beyond

Lightweight J2EE Framework

Creating Manageable Systems With JMX, Spring, AOP, and Groovy

Transcription:

Enterprise Java Development using JPA, Hibernate and Spring Srini Penchikala Detroit JUG Developer Day Conference November 14, 2009

About the Speaker Enterprise Architect Writer, Speaker, Editor (InfoQ) Working with Java since 1996, JEE (2000), SOA (2006), & PowerPoint since July 2009 Current: Agile Architectures, Domain-Driven Design, Architecture Enforcement, Model Driven Development, SOA Future: Security Architecture, Role of DSL's in Architecture Enforcement 2

Goals for this Presentation What are the essential ingredients of JEE development recipe and How Spring Portfolio helps in implementing a JEE project 3

Format Interactive Demos Duration: ~120 minutes Discussion oriented tutorial Not a hands-on workshop Q & A 4

Before we start How many are currently using Spring? Level of experience 5

Agenda (1/2) Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 6

Agenda (2/2) Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 7

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 8

Tutorial Application (1/5) Loan processing application Demonstrates how to use JPA, Hibernate and Spring in developing enterprise Java applications Covers JEE application concerns that developers run into in real-world applications 9

Tutorial Application (2/5) Loan processing application Demonstrates how to use JPA, Hibernate and Spring in developing enterprise Java applications JEE application concerns that developers run into in real-world applications: Application Security Persistence Transaction Management Data Binding/ Data Validation Web Services (REST) 10

Tutorial Application (3/5) Tools: JDK 1.6 Maven Eclipse Testing: JUnit 4.4 Mockito Spring Test Module 11

Tutorial Application (4/5) Technologies (non-spring): JPA Hibernate JAXB Jetty Dozer HSQL JBossCache/EHCache 12

Tutorial Application (5/5) Technologies (Spring): Spring Core (IoC) Spring AOP Spring JPA Spring Security Spring Modules 13

How to build sample application Checkout the code from Google Project (https://enterprise-javaspring.googlecode.com/svn/trunk) Install JDK, Maven and Eclipse (if needed) Modify setbaseenv.bat file To compile and unit test: mvn clean compile test To run the web application: mvn package jetty:run 14

Agenda (1/2) Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 15

Spring Framework Light-weight JEE middleware framework Separation of concerns (business v. infrastructure) POJO Based Design Business domain first, infrastructure concerns second Agile Development and Testing 16

Spring Portfolio Projects Spring Core Spring AOP Spring Security Spring MVC/Spring WebFlow 17

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 18

Why Spring (1/3) Test Driven Development Unit testing in isolation Mock objects System integration testing support

Why Spring (2/3) Agile Software Development (Scrum) Iterative Design, Development, Unit Testing and Refactoring Modular Application Architecture POJO Programming Model

Why Spring (3/3) Domain-Driven Design

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 22

Architecture Layers User Interface Application Domain Infrastructure 23

Layered Architecture Example 24

Typical J2EE Architecture Model Application Controller HTTP Session Management Facade Transaction Management Caching Data Access Data Access Object Persistence Data Store Domain Object* Database Notes: No real Domain Layer Business Logic in Façade Layer (Stateless Session Beans) Direct Access to Data Access Objects (CRUD logic is infrastructure not business) *Domain objects are really Persistence classes with getters/setters Infrastructure concerns have overtaken/ overshadowed the domain concerns 25

The Problem Architects/Developers are thinking only about infrastructure Most of the development time is still spent on writing plumbing code instead of real business logic We have lost real OOD/OOP 26

Domain Driven Architecture Application Controller Facade Infrastructure Domain Domain HTTP Session Management Remoting Persistence Caching Transaction Management Security (Authentication & Authorization Asynchronous Messaging Data Access/ Persistence Data Access Object Data Store Database Notes: All Layers support POJO based design Controller and Façade layers are consumers of Domain Classes Business Logic only in Domain Classes No direct Access to DAO s except from Domain Classes Domain First, Infrastructure Second Infrastructure concerns are implemented via DI, AOP, Annotations 27

Application Architecture Layers

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 29

Domain Driven Design What: Domain Driven Design (DDD) is about mapping business domain concepts into software artifacts. Why: To create better software by focusing on a model of the domain rather than the technology. 30

Advantages Promotes high cohesion and low coupling in the application code Easy to test domain components Business (domain) logic is isolated from nondomain and infrastructure code Adding/changing services does not influence the domain or other services 31

Domain Elements Domain objects: Instances of real entities which hold knowledge or activity of business domain Entities: Objects defined by their identity, which remains same throughout life of software (Customer, Account) Value Objects Immutable objects that have no identity & are used to describe an attribute of another object (Product, State lookup) (Domain) Services Objects that have no state & only have a defined behavior that s not part of any domain object (FundTransfer service, Loan Interest Calculation) 32

Other DDD Elements Module (Package): A method of organizing related concepts and tasks in order to reduce complexity. Domain object Lifecycle is managed by: Aggregate Factory Repository 33

Design Recipe Object Oriented Programming (OOP) Dependency Injection (DI) Aspect-oriented Programming (AOP) Annotations 34

Domain Elements and OOP Domain Element Entity, Value Object, Aggregate Data Transfer Object Service, Repository Encapsulation State and Behavior State only Behavior only 35

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 36

Dependency Injection (DI) aka Inversion of Control (IoC) Based on Hollywood Principle Decouple and manage the dependencies of the components in the application DI Frameworks: Spring Google Guice Pico Container 37

DI Use Cases Service Domain Classes Transaction Manager Domain Data Access Object (DAO) DAO class Data Source JPA Entity Manager 38

Domain Object DI Domain objects not instantiated by Spring IoC container @Configurable annotation 39

DEMO 40

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 41

Aspect-oriented Programming Allows developers to add behavior to objects in a non-obtrusive manner through use of static and dynamic crosscutting Main goal is to code cross-cutting concerns in separate modules and apply them in a declarative way 42

AOP Use Cases Spring Framework Built-In Aspects Transaction Management Security Custom Aspects Profiling Caching Rules Architecture Governance/Policy Enforcement 43

DEMO 44

Agenda Introduction Tutorial Sample Application Spring Framework Why Spring? JEE Application Architecture Domain-Driven Design Dependency Injection Aspect-oriented Programming Annotations 45

Annotations Added in Java SE 5.0 as Java Metadata facility (JSR 175) Provide a way to add metadata to program elements Defined by nearly every recent JSR standard Also include a mechanism for adding custom annotations to the Java code 46

Annotations For Domain Elements Layer Domain Element Annotation Domain Entity, Value Object @Entity (JPA), @Configurable Domain Repository @Repository Domain Service @Service Application Controller @Controller All All @Component 47

Custom Annotations Use Cases: Caching Validation Implementation options: Reflection Annotation Processing Tool (APT) Byte-code Instrumentation (Javassist) Aspects/AOP (AspectJ and Spring AOP) 48

DEMO 49

Application Architecture Layers Database Data Access Domain Controller Presentation 50

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 51

Application Concerns Persistence Transaction Management Application Security (AuthN & AuthZ) Caching 52

Other Application Concerns Monitoring (JMX, Spring JMX) Conversational Web Applications (Web Flow) Asynchronous Messaging (JMS, MDP) Enterprise Integration (Spring Integration) Batch Processing (Spring Batch) * Not covered in this presentation 53

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 54

Persistence The Spring Way JDBC (Spring JDBC Template) JPA w/ Hibernate, OpenJPA, EclipseLink (TopLink) Spring JPA Utils & Data Source DI 55

DEMO 56

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 57

Transaction Management The Spring Way Declarative transaction semantics Similar to EJB3 transaction model and more Spring JTA Support Support for multiple transaction managers JDBC Hibernate JTA Transactions are managed in Service classes using @Transactional annotation 58

DEMO 59

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 60

Application Security Spring Security Module Declarative application security support Fits in very well with Spring Core framework Authentication Authorization URL level Domain Object Service Method JDBC and LDAP Authentication Providers JSR-250 compliant 61

Authentication Code Example 62

Authorization Code Example 63

DEMO 64

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 65

Ideal Web Application Framework Isolation from domain layer so presentation and domain layers can evolve independently Simple and Easy Data binding between Domain, Controller and Presentation layers Support for data validation that works in all layers w/o any additional coding Support for AJAX functionality Controller methods can be exposed as RESTful Web Services w/o extra coding or configuration 66

MVC Spring MVC Annotation-based Controller Configuration (@Controller) @RequestMapping @ModelAttribute @RequestParam @SessionAttributes 67

DEMO 68

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 69

Data Binding and Validation Data binding using @ModelAttribute @InitBinder Example: FeeController Validation: Declaration Validation Logic Custom Validation Error Messages JSR 303 support 70

DEMO 71

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 72

Web Services Support Spring WS Spring 3.0 REST support Message Converters RestTemplate 73

Project Lifecycle Diagram 74

Agenda Application Concerns Persistence Transaction Management Application Security MVC Validation Web Services (REST) Conclusions 75

Conclusions Domain First, Infrastructure Second Layered Architecture & Separation of Concerns POJO s are fun to work with again Balance between the right vs. the right now Java EE 6 release focuses on development & deployment simplicity JPA 2.0, EJB 3.1, Spring 3.0 76

References (1/2) Sample Application Project Site (https://enterprise-javaspring.googlecode.com/svn/trunk) Spring Framework Reference Manual (http://static.springsource.org/spring/docs/3.0.x/springframework-reference/html/) Spring In Action 3 rd Edition (http://www.manning.com/walls4/) Domain Driven Design and Development In Practice (http://www.infoq.com/articles/ddd-in-practice) Domain-Driven Design Website (http://www.domaindrivendesign.org/) 77

References (2/2) Domain-Driven Design by Eric Evans Applying Domain-Driven Design and Patterns, Jimmy Nilsson Patterns of Enterprise Application Architecture, Martin Fowler Can DDD be Adequately Implemented Without DI and AOP (http://www.infoq.com/news/2008/02/ddd-di-aop) 78

Contact Information Domain-Driven Design and Enterprise Architecture articles on InfoQ website: http://www.infoq.com srinipenchikala@gmail.com http://srinip2007.blogspot.com @srinip 11/21/2009 Srini Penchikala 79

Q & A 80

Thank You Thank you for your attention Feedback survey Happy Holidays 81