Top Banner
Legacy Database Integration with Hibernate & Grails
20

Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

May 24, 2020

Download

Documents

dariahiddleston
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: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails

Page 2: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Jason Rudolph Grails Committer Principal @ Relevance Author

Introduction

Page 3: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

What Are We Getting Ourselves Into?

vs.Convention-over-

configuration Legacy Schemas

Opinionated Software

Old Designs and Ideas

vs.

Page 4: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

DAO

Page 5: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

DAOs Considered Harmful

Grails Object-Relational Mapping (GORM) Rich relationship model Declarative validation Powerful query support Easy scaffolding

Page 6: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Conventional ThinkingDemo

Page 7: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Defying Conventional Wisdom

Non-conforming table/column names

Custom sequences

Complex keys

Advanced mappings

Page 8: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Certificate of NonconformityDemo

Page 9: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Grails + Hibernate XMLStep 1

Review existing schema

Sketch out desired object model Favor object-oriented thinking The database shall bend

Define domain classes

Page 10: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

No Schema Left BehindDemo

Page 11: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Prepare HBM file for each deviant table

Define hibernate.cfg.xml

Test!

Grails + Hibernate XMLStep 2

Page 12: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Why Hibernate XML?

Standard Hibernate artifacts Reuse your existing mappings? Existing tool support Full power of GORM

Dynamic persistence methods Constraints Scaffolding

Page 13: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Fewer Sharp Corners?

Page 14: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

GORM DSL<Brand new for 1.0!>

class Knight { // ...

static mapping = { table ‘knights’ version false id column:‘knight_id’

columns { numDragonsSlain column:‘dragon_count’

// ...}

}}

Page 15: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

More Declarative DSL Goodness

ID generation Lazy/eager fetching Inheritance strategy Index definitions Caching

Page 16: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Other Mapping Strategies

Hibernate (EJB3-Style) Annotations infoq.com/articles/grails-ejb-tutorial

JPA (Coming soon)

Page 17: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Still More to Explore

GORM outside of Grails grails.org/gorm+-+standalone+gorm

Custom user types grails.org/hibernate+integration

Page 18: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Resources

GORM Documentation grails.org/gorm

GORM DSL grails.org/GORM+-+Mapping+DSL

Page 19: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Resources (cont’d)

Mailing List grails.org/mailing+lists

Hibernate Tools hibernate.org/255.html

Page 20: Legacy Database Integration with Hibernate & Grails...Legacy Database Integration with Hibernate & Grails jasonrudolph.com Grails + Hibernate XML Step 1 Review existing schema Sketch

Legacy Database Integration with Hibernate & Grails jasonrudolph.com

Slides & Examples Available@

jasonrudolph.com/downloads

This presentation is published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5.

(Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.)