O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Not Just ORM:
Powerful Hibernate ORM
Features and Capabilities
Brett Meyer
Senior Software Engineer
Hibernate ORM, Red Hat
Brett Meyer
• Hibernate ORM
– ORM 4 & 5 development
– Hibernate OSGi
– Developer community engagement
– Red Hat support, H...
github.com/brmeyer
/HibernateDemos

slideshare.net/brmeyer
ORM? JPA?
• ORM: Object/Relational Mapping
– Persistence: Data objects outlive the JVM app
– Maps Java POJOs to relational...
Overview
•
•
•
•
•
•
•
•
•

Multi-Tenancy
Value Generation
Hibernate Spatial
Hibernate Envers
Hibernate OSGi
Hibernate Sea...
Multi-Tenancy
Multi-Tenancy
•
•
•
•

1 ORM instance
Multiple concurrent clients
Data specific to each tenant
Legacy
– Separate SessionFa...
Hibernate ORM
Multi-Tenancy
•
•
•
•

Strategy selection is global
Tenant identifier provided when opening a Session
Works ...
Hibernate ORM
Multi-Tenancy Strategies
• Physically separated databases
– 1 JDBC connection pool per tenant
– Pool selecte...
Hibernate ORM
Multi-Tenancy Strategies
• Single database and schema
– Data partitioned by discriminator value
– Discrimina...
Hibernate ORM
Multi-Tenancy
• DEMO
• Questions?
Value Generation
Value Generation (Legacy)
• Limited to in-database value generation
on insert/update
• Properties marked with @Generated
i...
Hibernate ORM
Value Generation
•
•
•
•

New, expanded support in ORM 4.3
Supports legacy in-DB generation, but also in-mem...
Hibernate Spatial
Hibernate Spatial
• Currently 3rd party, but pulling in as a new ORM module in 5
• Originally created by Karel Maesen (geo...
Hibernate Spatial (cont'd)
• Properties use JTS Geometry types
– Point
– LineString
– Polygon
– etc.

• Adds HQL functions...
Hibernate Spatial (cont'd)
• Translates between “Well-known text” (WKT) and
Geometry types
– Spatial object markup languag...
Hibernate Envers
Hibernate Envers
• Provides historical versioning and auditing (“SCM for data”)
• Each transaction == a “revision”
• Revis...
Hibernate Envers (cont'd)
• Revision info
– Default: simple internal entity stored in REVINFO table
– Revision # and revis...
Hibernate Envers (cont'd)
• Revision properties
– Track the entity properties that were changed in each revision
– Disable...
Hibernate OSGi
Hibernate OSGi
• OSGi?
• Provide only the OSGi manifest and hacky workarounds <-NO!
• Emphasize doing things “the OSGi way...
Hibernate OSGi (cont'd)
• 3 supported environments
– Enterprise OSGi Managed JPA
• Container discovers and manages persist...
Hibernate Search
Hibernate Search
• Full-text search on the DB
– Bad performance
– CPU/IO overhead

• Offload full-text queries to Hibernat...
Hibernate Search (cont'd)
• Annotate entities with @Indexed
• Annotate properties with @Field
– Index the text: index=Inde...
Hibernate OGM &
Hibernate Validator
Hibernate OGM & Validator
• Hibernate OGM:
– ORM/JPA support for NoSQL
– Infinispan, EHCache, MongoDB, Neo4j

• Hibernate ...
Hibernate Shards
Hibernate Shards
• Started as a Google team's 20% project
• Horizontal partitioning across multiple databases
• Flexible s...
How to Help:
hibernate.org
/orm/contribute
Hibernate ORM:
Tips, Tricks, and
Performance Techniques

Tomorrow, 1pm,
Ballroom D
QUESTIONS?
•
•
•
•

Q&A
#hibernate or #hibernate-dev (brmeyer)
@brettemeyer
+brettmeyer
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Próximos SlideShares
Carregando em…5
×

Not Just ORM: Powerful Hibernate ORM Features and Capabilities

DevNexus 2014

Hibernate has always revolved around data, ORM, and JPA. However, it’s much more than that. Hibernate has grown into a family of projects and capabilities, extending well beyond the traditional ORM/JPA space.

This talk will present powerful features provided both by Hibernate ORM, as well as third-party extensions. Some capabilities are brand new, while others are older-but-improved. Topics include multiple-tenancy, geographic data, auditing/versioning, sharding, OSGi, and integration with additional Hibernate projects. The talk will include live demonstrations.

Not Just ORM: Powerful Hibernate ORM Features and Capabilities

  1. 1. Not Just ORM: Powerful Hibernate ORM Features and Capabilities Brett Meyer Senior Software Engineer Hibernate ORM, Red Hat
  2. 2. Brett Meyer • Hibernate ORM – ORM 4 & 5 development – Hibernate OSGi – Developer community engagement – Red Hat support, Hibernate engineering lead • Other contributions – Apache Camel – Infinispan • Contact me – @brettemeyer or +brettmeyer – Freenode #hibernate or #hibernate-dev (brmeyer)
  3. 3. github.com/brmeyer /HibernateDemos slideshare.net/brmeyer
  4. 4. ORM? JPA? • ORM: Object/Relational Mapping – Persistence: Data objects outlive the JVM app – Maps Java POJOs to relational databases – Supports OO concepts: inheritance, object identity, etc. – Navigate data by walking the object graph, not the explicit relational model • JPA: Java Persistence API • Hibernate ORM provides its own native API, in addition to full JPA support • Annotations and XML
  5. 5. Overview • • • • • • • • • Multi-Tenancy Value Generation Hibernate Spatial Hibernate Envers Hibernate OSGi Hibernate Search Hibernate OGM & Validator Hibernate Shards Ask questions after each section!
  6. 6. Multi-Tenancy
  7. 7. Multi-Tenancy • • • • 1 ORM instance Multiple concurrent clients Data specific to each tenant Legacy – Separate SessionFactories for each tenant – Application-provided Connections (given when opening a Session) – Big schemas or many tenants = huge footprint
  8. 8. Hibernate ORM Multi-Tenancy • • • • Strategy selection is global Tenant identifier provided when opening a Session Works with 2LC: identifier used in cache data key Custom impls: – MultiTenantConnectionProvider: required for physical and schema separated (required) – CurrentTenantIdentifierResolver: required for opening a Session without providing the tenant id (explicitly or Session#getCurrentSession)
  9. 9. Hibernate ORM Multi-Tenancy Strategies • Physically separated databases – 1 JDBC connection pool per tenant – Pool selected based on tenant identifier • Single database, separate schemas – Option #1 • Similar to physically separated • 1 JDBC connection pool per tenant • Provides schema through the connection URL or pool – Option #2: • 1 JDBC connection pool using a default schema • Each Connection altered with SQL “SET SCHEMA” prior to use
  10. 10. Hibernate ORM Multi-Tenancy Strategies • Single database and schema – Data partitioned by discriminator value – Discriminator complexity varies – Each SQL statement altered to include the discriminator – Not yet implemented (planned for ORM 5) – Alternative: @FilterDef/@Filter w/ a tenantId as a param
  11. 11. Hibernate ORM Multi-Tenancy • DEMO • Questions?
  12. 12. Value Generation
  13. 13. Value Generation (Legacy) • Limited to in-database value generation on insert/update • Properties marked with @Generated immediately selected
  14. 14. Hibernate ORM Value Generation • • • • New, expanded support in ORM 4.3 Supports legacy in-DB generation, but also in-mem Create custom annotations! ORM provides built in generators – @Generated: legacy, providing in-database generation – @CreationTimestamp: set only once when owning entity is saved for the first time – @UpdateTimestamp: set any time owning entity is saved – @GeneratorType: provide custom in-memory generator and define “when” • DEMO • Questions?
  15. 15. Hibernate Spatial
  16. 16. Hibernate Spatial • Currently 3rd party, but pulling in as a new ORM module in 5 • Originally created by Karel Maesen (geovise.com) • Java Topology Suite (JTS) – OpenGIS Simple Feature Spec (SFS) & SQL/MM Spatial (extends SFS) – Oracle, Postgres, MySQL, MS SQL, H2, etc. all implement the specs – Attempts to provide abstract, cross-platform geo data, but diffs between them • geolatte-geom – Developed/maintained by Karel – Improvement over JTS – Fully interoperable with JTS – Support for lat/lon geographies – Additional Dialect differences
  17. 17. Hibernate Spatial (cont'd) • Properties use JTS Geometry types – Point – LineString – Polygon – etc. • Adds HQL functions for Dialect-supported methods – Same functions also implemented as Criteria API Criterions – ex: "select e from Event e where within(e.location, :filter) = true" (:filter is a Geometry) – http://www.hibernatespatial.org/documentation/03-dialects/0 1-overview/
  18. 18. Hibernate Spatial (cont'd) • Translates between “Well-known text” (WKT) and Geometry types – Spatial object markup language – 2D and 3D – ex: “POINT (30 10)”, “POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))” • Coordinate system transformations possible in queries • Does not require JDBC extension drivers (ex: Oracle SDOAPI.jar or Postgres postgis.jar) • DEMO • Questions?
  19. 19. Hibernate Envers
  20. 20. Hibernate Envers • Provides historical versioning and auditing (“SCM for data”) • Each transaction == a “revision” • Revision #s are global --> querying for a historical snapshot of the entire database is possible • Requires – @Audited on the entity or individual properties – [entity]_AUD tables to store the historical data (DDL created automated if using hbm2ddl, otherwise it’s exportable) • Duplicate data? Yes. • Powerful queries/capabilities > cheap mem • Highly configurable
  21. 21. Hibernate Envers (cont'd) • Revision info – Default: simple internal entity stored in REVINFO table – Revision # and revision timestamp – Override with custom @RevisionEntity & RevisionListener (add other useful fields: IP address, “blame”, etc.) • Revision entity types – Track the entity types that were changed in each revision – Disabled by default: requires querying tables for changed data – Can be overridden by implementing EntityTrackingRevisionListener on your RevisionEntity
  22. 22. Hibernate Envers (cont'd) • Revision properties – Track the entity properties that were changed in each revision – Disabled by default: requires querying tables for changed data – Adds boolean columns to audit tables • Queries – Snapshot of entity states at a given revision (horizontal) – Revisions at which entities changed (vertical) • DEMO • Questions? • Conditional auditing – Default: Envers auditing reacts to Hibernate ORM events – Disable hibernate.listeners.envers.autoRegister, create your own listeners, wire them in using Integrator
  23. 23. Hibernate OSGi
  24. 24. Hibernate OSGi • OSGi? • Provide only the OSGi manifest and hacky workarounds <-NO! • Emphasize doing things “the OSGi way” – Dynamic environment – Scoping • Limited visibility into the container • No scanning all bundles • Reduced conflicts, allows concurrent instances, etc. – OSGi services • Isolated in hibernate-osgi module (no pervasive dependencies or OSGi code)
  25. 25. Hibernate OSGi (cont'd) • 3 supported environments – Enterprise OSGi Managed JPA • Container discovers and manages persistence units and EntityManagerFactories • Similar to many app servers, Spring, etc. • Ex: Apache Aries JPA – Un-managed JPA • Direct use of hibernate-entitymanager • EntityManagerFactories created through OSGi services – Native • Direct use of hibernate-core • SessionFactories created through OSGi services • Quickstarts • Questions?
  26. 26. Hibernate Search
  27. 27. Hibernate Search • Full-text search on the DB – Bad performance – CPU/IO overhead • Offload full-text queries to Hibernate Search engine – Fully indexed – Horizontally scalable • Based on Apache Lucene • “Google for your entities”
  28. 28. Hibernate Search (cont'd) • Annotate entities with @Indexed • Annotate properties with @Field – Index the text: index=Index.YES – “Analyze” the text: analyze=Analyze.YES • • • • • Lucene analyzer Chunks sentences into words Lowercase all of them Exclude common words (“a”, “the”) Stemming
  29. 29. Hibernate OGM & Hibernate Validator
  30. 30. Hibernate OGM & Validator • Hibernate OGM: – ORM/JPA support for NoSQL – Infinispan, EHCache, MongoDB, Neo4j • Hibernate Validator – Bean Validation impl, but extended – Both annotation and XML based – @NotNull, @Size(min = 2, max = 14), @Min(2), etc.
  31. 31. Hibernate Shards
  32. 32. Hibernate Shards • Started as a Google team's 20% project • Horizontal partitioning across multiple databases • Flexible sharding strategies, both provided and custom • Supports virtual shards: simplifies re-sharding • Typical Hibernate ORM usage: HQL, Criteria, etc. • Last supported ORM version: 3.6.x • Currently has upgrade momentum – contact me if interested!
  33. 33. How to Help: hibernate.org /orm/contribute
  34. 34. Hibernate ORM: Tips, Tricks, and Performance Techniques Tomorrow, 1pm, Ballroom D
  35. 35. QUESTIONS? • • • • Q&A #hibernate or #hibernate-dev (brmeyer) @brettemeyer +brettmeyer

    Seja o primeiro a comentar

    Entre para ver os comentários

  • PeterChen7

    Apr. 28, 2015
  • hubenlv

    Aug. 10, 2015
  • mavlarn

    Oct. 7, 2015
  • tmnasim

    Dec. 15, 2015
  • sky_wu

    Mar. 14, 2016
  • chesheng

    Mar. 14, 2016
  • itplayer

    Mar. 14, 2016
  • ttlqudan

    Nov. 15, 2016
  • jobinjose5095

    Dec. 22, 2016
  • waleoyediran1

    Jan. 22, 2017
  • jcfrancisco17

    May. 9, 2017
  • yoonesrahimi

    Aug. 28, 2017
  • thiago_monteiro

    Apr. 1, 2018
  • bsubra786

    May. 5, 2019
  • LarsBreddemann

    Feb. 2, 2020
  • DavideOlisti

    May. 20, 2020

DevNexus 2014 Hibernate has always revolved around data, ORM, and JPA. However, it’s much more than that. Hibernate has grown into a family of projects and capabilities, extending well beyond the traditional ORM/JPA space. This talk will present powerful features provided both by Hibernate ORM, as well as third-party extensions. Some capabilities are brand new, while others are older-but-improved. Topics include multiple-tenancy, geographic data, auditing/versioning, sharding, OSGi, and integration with additional Hibernate projects. The talk will include live demonstrations.

Vistos

Vistos totais

18.654

No Slideshare

0

De incorporações

0

Número de incorporações

327

Ações

Baixados

488

Compartilhados

0

Comentários

0

Curtir

16

×