SlideShare a Scribd company logo
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
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, Hibernate engineering lead

• Other contributions
– Apache Camel
– Infinispan

• Contact me
– @brettemeyer or +brettmeyer
– Freenode #hibernate or #hibernate-dev (brmeyer)
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 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
Overview
•
•
•
•
•
•
•
•
•

Multi-Tenancy
Value Generation
Hibernate Spatial
Hibernate Envers
Hibernate OSGi
Hibernate Search
Hibernate OGM & Validator
Hibernate Shards
Ask questions after each section!
Multi-Tenancy
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
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)
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
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
Hibernate ORM
Multi-Tenancy
• DEMO
• Questions?
Value Generation
Value Generation (Legacy)
• Limited to in-database value generation
on insert/update
• Properties marked with @Generated
immediately selected
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?
Hibernate Spatial
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
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/
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?
Hibernate Envers
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
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
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
Hibernate OSGi
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)
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?
Hibernate Search
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”
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
Hibernate OGM &
Hibernate Validator
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.
Hibernate Shards
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!
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

More Related Content

What's hot (20)

AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
Mikhail Egorov
 
MySQL on AWS RDS
MySQL on AWS RDSMySQL on AWS RDS
MySQL on AWS RDS
Mydbops
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
Koichi Sakata
 
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRS
Steve Pember
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
Arvind Devaraj
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data grids
Max Alexejev
 
C* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
C* Summit 2013: How Not to Use Cassandra by Axel LiljencrantzC* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
C* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
DataStax Academy
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013
Vladimir Ivanov
 
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VMIntrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Kris Mok
 
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
AWSKRUG - AWS한국사용자모임
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
Mohamed Farouk
 
Twitter의 snowflake 소개 및 활용
Twitter의 snowflake 소개 및 활용Twitter의 snowflake 소개 및 활용
Twitter의 snowflake 소개 및 활용
흥배 최
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
Brendan Gregg
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향
Young-Ho Cho
 
How Booking.com avoids and deals with replication lag
How Booking.com avoids and deals with replication lagHow Booking.com avoids and deals with replication lag
How Booking.com avoids and deals with replication lag
Jean-François Gagné
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
Arawn Park
 
ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기
Yungon Park
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
Mikhail Egorov
 
MySQL on AWS RDS
MySQL on AWS RDSMySQL on AWS RDS
MySQL on AWS RDS
Mydbops
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
Koichi Sakata
 
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRS
Steve Pember
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
Arvind Devaraj
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data grids
Max Alexejev
 
C* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
C* Summit 2013: How Not to Use Cassandra by Axel LiljencrantzC* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
C* Summit 2013: How Not to Use Cassandra by Axel Liljencrantz
DataStax Academy
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013
Vladimir Ivanov
 
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VMIntrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Kris Mok
 
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
Amazon EKS로 간단한 웹 애플리케이션 구축하기 - 김주영 (AWS) :: AWS Community Day Online 2021
AWSKRUG - AWS한국사용자모임
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
Mohamed Farouk
 
Twitter의 snowflake 소개 및 활용
Twitter의 snowflake 소개 및 활용Twitter의 snowflake 소개 및 활용
Twitter의 snowflake 소개 및 활용
흥배 최
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
Brendan Gregg
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향
Young-Ho Cho
 
How Booking.com avoids and deals with replication lag
How Booking.com avoids and deals with replication lagHow Booking.com avoids and deals with replication lag
How Booking.com avoids and deals with replication lag
Jean-François Gagné
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
Arawn Park
 
ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기
Yungon Park
 

Similar to Not Just ORM: Powerful Hibernate ORM Features and Capabilities (20)

hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
Patiento Del Mar
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
hibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdfhibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdf
Patiento Del Mar
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
Akshay Ballarpure
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Why hibernater1
Why hibernater1Why hibernater1
Why hibernater1
rajeevkuruganti
 
Basic Hibernate Final
Basic Hibernate FinalBasic Hibernate Final
Basic Hibernate Final
Rafael Coutinho
 
Hibernate
HibernateHibernate
Hibernate
Preetha Ganapathi
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research setting
Csaba Toth
 
Hibernate
HibernateHibernate
Hibernate
Murali Pachiyappan
 
Module-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptxModule-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptx
ViratKohli78
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
Toby Samples
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
patinijava
 
What is hibernate?
What is hibernate?What is hibernate?
What is hibernate?
kanchanmahajan23
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
Joe Jacob
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
Sagar Verma
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Hibernate complete notes_by_sekhar_sir_javabynatara_jHibernate complete notes_by_sekhar_sir_javabynatara_j
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Satya Johnny
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
Patiento Del Mar
 
hibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdfhibernateormoverview-140501154227-phpapp02.pdf
hibernateormoverview-140501154227-phpapp02.pdf
Patiento Del Mar
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research setting
Csaba Toth
 
Module-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptxModule-3 for career and JFSD ppt for study.pptx
Module-3 for career and JFSD ppt for study.pptx
ViratKohli78
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
Toby Samples
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
patinijava
 
Hibernate jj
Hibernate jjHibernate jj
Hibernate jj
Joe Jacob
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
Sagar Verma
 
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Hibernate complete notes_by_sekhar_sir_javabynatara_jHibernate complete notes_by_sekhar_sir_javabynatara_j
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Satya Johnny
 
Ad

Recently uploaded (20)

Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Ad

Not Just ORM: Powerful Hibernate ORM Features and Capabilities

  • 2. Not Just ORM: Powerful Hibernate ORM Features and Capabilities Brett Meyer Senior Software Engineer Hibernate ORM, Red Hat
  • 3. 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)
  • 5. 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
  • 6. Overview • • • • • • • • • Multi-Tenancy Value Generation Hibernate Spatial Hibernate Envers Hibernate OSGi Hibernate Search Hibernate OGM & Validator Hibernate Shards Ask questions after each section!
  • 8. 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
  • 9. 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)
  • 10. 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
  • 11. 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
  • 14. Value Generation (Legacy) • Limited to in-database value generation on insert/update • Properties marked with @Generated immediately selected
  • 15. 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?
  • 17. 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
  • 18. 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/
  • 19. 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?
  • 21. 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
  • 22. 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
  • 23. 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
  • 25. 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)
  • 26. 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?
  • 28. 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”
  • 29. 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
  • 31. 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.
  • 33. 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!
  • 35. Hibernate ORM: Tips, Tricks, and Performance Techniques Tomorrow, 1pm, Ballroom D