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

Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Apr 25, 2018

Download

Documents

vukhanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Enterprise Java Development using

JPA, Hibernate and Spring

Srini Penchikala

Detroit JUG Developer Day Conference

November 14, 2009

Page 2: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

2

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

Page 3: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

3

Goals for this Presentation

“What” are the essential ingredients of JEE development recipe and “How” Spring Portfolio helps in implementing a JEE project

Page 4: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

4

Format

Interactive

Demos

Duration: ~120 minutes

Discussion oriented tutorial

Not a hands-on workshop

Q & A

Page 5: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

5

Before we start…

How many are currently using Spring?

Level of experience

Page 6: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

6

Agenda (1/2) Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 7: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

7

Agenda (2/2) Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 8: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

8

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 9: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

9

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

Page 10: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

10

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)

Page 11: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

11

Tutorial Application (3/5)

Tools:

JDK 1.6

Maven

Eclipse

Testing:

JUnit 4.4

Mockito

Spring Test Module

Page 12: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

12

Tutorial Application (4/5)

Technologies (non-Spring):

JPA

Hibernate

JAXB

Jetty

Dozer

HSQL

JBossCache/EHCache

Page 13: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

13

Tutorial Application (5/5)

Technologies (Spring):

Spring Core (IoC)

Spring AOP

Spring JPA

Spring Security

Spring Modules

Page 14: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

14

How to build sample application

Checkout the code from Google Project

(https://enterprise-java-

spring.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

Page 15: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

15

Agenda (1/2) Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 16: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

16

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

Page 17: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

17

Spring Portfolio Projects

Spring Core

Spring AOP

Spring Security

Spring MVC/Spring WebFlow

Page 18: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

18

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 19: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Why Spring (1/3)

Test Driven Development

Unit testing in isolation

Mock objects

System integration testing support

Page 20: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Why Spring (2/3)

Agile Software Development (Scrum)

Iterative Design, Development, Unit Testing and

Refactoring

Modular Application Architecture

POJO Programming Model

Page 21: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Why Spring (3/3)

Domain-Driven Design

Page 22: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

22

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 23: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

23

Architecture Layers

User Interface

Application

Domain

Infrastructure

Page 24: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

24

Layered Architecture Example

Page 25: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

25

Typical J2EE Architecture ModelController

Facade

Data Access Object

Domain Object*

Database

Application

Data Access

Persistence

Data Store

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

Transaction Management

Caching

HTTP

Session Management

Page 26: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

26

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

Page 27: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

27

Domain Driven Architecture

Controller

Facade

Domain

Data Access Object

Database

Application

Domain

Data Access/

Persistence

Data Store

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

Infrastructure

· HTTP

· Session Management

· Remoting

· Persistence

· Caching

· Transaction Management

· Security (Authentication &

Authorization

· Asynchronous Messaging

Page 28: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Application Architecture Layers

Page 29: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

29

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 30: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

30

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.

Page 31: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

31

Advantages

Promotes high cohesion and low coupling in the

application code

Easy to test domain components

Business (domain) logic is isolated from non-

domain and infrastructure code

Adding/changing services does not influence the

domain or other services

Page 32: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

32

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)

Page 33: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

33

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

Page 34: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

34

Design Recipe

Object Oriented Programming (OOP)

Dependency Injection (DI)

Aspect-oriented Programming (AOP)

Annotations

Page 35: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

35

Domain Elements and OOP

Domain Element Encapsulation

Entity,Value Object,Aggregate

State and Behavior

Data Transfer Object State only

Service, Repository Behavior only

Page 36: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

36

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 37: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

37

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

Page 38: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

38

DI Use Cases

Service

Domain Classes

Transaction Manager

Domain

Data Access Object (DAO)

DAO class

Data Source

JPA Entity Manager

Page 39: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

39

Domain Object DI

Domain objects not instantiated by Spring IoC

container

@Configurable annotation

Page 40: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

40

DEMO

Page 41: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

41

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 42: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

42

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

Page 43: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

43

AOP Use Cases

Spring Framework Built-In Aspects

Transaction Management

Security

Custom Aspects

Profiling

Caching

Rules

Architecture Governance/Policy Enforcement

Page 44: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

44

DEMO

Page 45: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

45

Agenda Introduction

Tutorial Sample Application

Spring Framework

Why Spring?

JEE Application Architecture

Domain-Driven Design

Dependency Injection

Aspect-oriented Programming

Annotations

Page 46: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

46

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

Page 47: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

47

Annotations For Domain Elements

Layer Domain Element Annotation

DomainEntity,

Value Object

@Entity (JPA),

@Configurable

Domain Repository @Repository

Domain Service @Service

Application Controller @Controller

All All @Component

Page 48: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

48

Custom Annotations

Use Cases:

Caching

Validation

Implementation options:

Reflection

Annotation Processing Tool (APT)

Byte-code Instrumentation (Javassist)

Aspects/AOP (AspectJ and Spring AOP)

Page 49: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

49

DEMO

Page 50: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

50

Application Architecture Layers

Database

Data Access

Domain

Controller

Presentation

Page 51: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

51

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 52: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

52

Application Concerns

Persistence

Transaction Management

Application Security (AuthN & AuthZ)

Caching

Page 53: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

53

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

Page 54: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

54

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 55: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

55

Persistence – The Spring Way

JDBC (Spring JDBC Template)

JPA w/ Hibernate, OpenJPA, EclipseLink (TopLink)

Spring JPA Utils & Data Source DI

Page 56: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

56

DEMO

Page 57: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

57

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 58: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

58

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

Page 59: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

59

DEMO

Page 60: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

60

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 61: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

61

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

Page 62: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

62

Authentication

Code Example

Page 63: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

63

Authorization

Code Example

Page 64: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

64

DEMO

Page 65: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

65

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 66: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

66

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

Page 67: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

67

MVC

Spring MVC

Annotation-based Controller Configuration

(@Controller)

@RequestMapping

@ModelAttribute

@RequestParam

@SessionAttributes

Page 68: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

68

DEMO

Page 69: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

69

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 70: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

70

Data Binding and Validation

Data binding using @ModelAttribute

@InitBinder

Example: FeeController

Validation:

Declaration Validation Logic

Custom Validation Error Messages

JSR 303 support

Page 71: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

71

DEMO

Page 72: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

72

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 73: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

73

Web Services Support Spring WS

Spring 3.0 REST support

Message Converters

RestTemplate

Page 74: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

74

Project Lifecycle Diagram

Page 75: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

75

Agenda Application Concerns

Persistence

Transaction Management

Application Security

MVC

Validation

Web Services (REST)

Conclusions

Page 76: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

76

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

Page 77: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

77

References (1/2) Sample Application Project Site (https://enterprise-java-

spring.googlecode.com/svn/trunk)

Spring Framework Reference Manual (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/)

Spring In Action 3rd 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/)

Page 78: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

78

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)

Page 79: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

Contact Information

Domain-Driven Design and Enterprise

Architecture articles on InfoQ

website: http://www.infoq.com

[email protected]

http://srinip2007.blogspot.com

@srinip

11/21/2009 Srini Penchikala79

Page 80: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

80

Q & A

Page 81: Enterprise Java Development using JPA, Hibernate and Springxa.yimg.com/.../name/EnterpriseJavaDevelopmentSpringHibernate.pdf · Enterprise Java Development using JPA, Hibernate and

81

Thank You

Thank you for your attention

Feedback survey

Happy Holidays