The Hibernate project: movingforward to NewSQL and
beyondSanne Grinovero Hibernate team
Sr Principal Software Engineer Red Hat
Take awayRefresh of Hibernate
Overview of Hibernate projects
What’s new?
What’s next?
Sanne Grinovero10+ years working with & on Hibernate
Team blog: Twitter:
in.relation.to@SanneGrinovero
Contributing to many more OSS projects in the data space
Apache Lucene, Elasticsearch
WildFly, JBoss Enterprise Application Server
In�nispan, JBoss Data Grid
Red Hat, 7+ years
How is it doing?
Let’s take some Maven stats
A,B,C,D are well known, economically viable projects, anonymisedfor their protection
… then include Hibernate stats
The scale had to change. {A..D} hare not missing.
Need to use a Logarithmicscale ?!
Looking at geographicalusage
Bangalore, India has most daily downloads
Guess China ?
Java Persistence APIJPA
Hibernate implements the standard interface
The Hibernate community in�uences next gen spec
Recruiters get very confused
Hibernate Portfolio
EcosystemJava EE (JPA implementation, JBoss EAP, WildFly)
Spring, Spring Boot
Groovy / Grails
Many many more!
loads of tooling
Hibernate ORM 5
CleanupBootstrap via well de�ned phases
Modularity
WildFly, OSGi, Java 9
extensions, integration points with ORM
Performance
Java8: Date and TimeDATE: java.time.LocalDate
TIME: java.time.LocalTime, java.time.OffsetTime
TIMESTAMP: java.time.Instant, java.time.LocalDateTime,java.time.OffsetDateTime and java.time.ZonedDateTime
AutoClosable, Genericstry ( Session session = sessionFactory.openSession() ) { Address address = session.get(Address.class, id); return address.getCity(); }
AutoClosable resources:
Session / StatelessSession
SessionFactory
ScrollableResults
Bytecode instrumentationSmarter change detection
Better Maven and Gradle support
Lazy loading of properties
sub-groups
Automatic bi-directional management
Association management -before
//Create relation Order order = new Order(); LineItem lineItem = new LineItem(); order.getLineItems().add( lineItem ); lineItem.setOrder( order );
//Relation established: lineItem.getOrder().getName();
Association management -after
//Create relation Order order = new Order(); LineItem lineItem = new LineItem(); order.getLineItems().add( lineItem ); //lineItem.setOrder( order ); Not required!
//Relation established: lineItem.getOrder().getName(); // NPE automatically prevented!
ByteBuddyNew ByteButty based enhancer, thanks to Rafael Winterhalter
To replace Javassist?
No runtime dependency
Based on ASM
SAP HANAA new exotic database…
Support for the powerful SAP HANA "in memory data platform"
Thanks to the SAP engineers!
Not just a new Dialect
What’s next?
Second level cacheOptimisations on the key types
Cache by reference (immutable entities)
JCache integration point
Second level cache, byreference
<property name="hibernate.cache.use_reference_entries" values=“true"/>
@Entity @Immutable @Cacheable @Cache( usage = CacheConcurrencyStrategy.READ_ONLY ) public class MyReferenceData { @Id private Integer id; private String name; private String theValue; .... }
Hibernate Search
Full-text searchInverted index
Object level
Clustered
Elasticsearch
What is new in 5+?Upgrade Lucene without breaking APIs
Signi�cant perf improvements
since 5.6: Elasticsearch !
WildFly Swarm and Spring Boot
An @Indexed @Entity@Indexed @Entity public class Address { @Id Integer id;
@Field String street1;
@Field(analyze=NO) @SortableField @Facet String city;
@IndexedEmbedded Country country;
... }
What’s coming in HibernateSearch 6?
Full abstraction from Lucene API
easier to plug additional full-text engines
HANA?
Hibernate OGMAn ORM for NOSQL ? OMG!!
JPA for NoSQLMongoDB
In�nispan
Neo4J
Redis
EhCache
Cassandra
CouchDB
First steps to get started<dependencies> <dependency> <groupId>org.hibernate.ogm</groupId> <artifactId>hibernate-ogm-neo4j</artifactId> </dependency> </dependencies>
<persistence> <persistence-unit name="ogm-neo4j" transaction-type="JTA"> <!-- Use Hibernate OGM provider: configuration will be transparent --> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <properties> <property name="hibernate.ogm.datastore.provider" value="neo4j"/> </properties> </persistence-unit> </persistence>
How to use OGMIt’s just JPA!
Java Persistence API
How to integrate with OGMIt’s just Hibernate!
Hibernate Validator
Bean Validation 2.0beanvalidation.org
class User { @Email String email; @Positive int age; @NotNull @Size(max=50) String firstName; }
@Stateless class UserService { public void createUser(@Valid @NotNull User user) { ... } }
Collections and othercontainers
public class User { @Size(max=10) public List<@NotNull @Email String> emails;
Optional<@Email String> defaultEmail; }
Validator 6: faster!http://in.relation.to/2017/10/31/bean-validation-benchmark-
revisited/
Hibernate Spatial
Hibernate Search Spatial vsHibernate Spatial
Hibernate Search uses Lucene indices outside of the database
can be combined with full-text, relevance "fuzzy logic"
Hibernate (ORM) Spatial uses RDBMS spatial functions
Oracle DB, Postgis (PostgreSQL), MySQL, GeoDB (H2),SQLServer, HANA
Code !org.hibernate:hibernate-spatial
hibernate.dialect=org.hibernate.spatial.dialect.postgis.Postgis
@Entity(name = "Event") public class Event {
@Id Long id;
@Type(type = "jts_geometry") Point location; }
QueryEvent event = entityManager.createQuery( "select e " + "from Event e " + "where within(e.location, :filter) = true", Event.class) .setParameter("filter", new WKTReader().read( "POLYGON((1 1,20 1,20 20,1 20,1 1))")) .getSingleResult();
Hibernate EnversIs getting more love
Hibernate 6 & beyond
Semantic Query ModelRefactoring Hibernate’s Type contract to unify Hibernate ORM, JPAand SQM type systems
Query and SQL execution performance
Migration to SQM for query interpretation/representationHQL/JPQL
(JPA) criteria queries
And much more… Jandex based annotation scanning
Always more performance
new Connection pool integrations
Using new tools extensively during design: JMH, java-object-layout
OSGi, Java 9: better modularity
Java 9Hibernate ORM → just works
Hibernate Validator → just works
Hibernate Search → just works
Hibernate OGM → WIP, depends on the NoSQL database
Not as modules yet!
ConclusionsReliable yet innovating
Comprehensive data platform
way beyond the 10y old relational-only ORM !
A friendly, open, deeply technical community
Q&ATry Hibernate *, you’ll love them
Contribute: feedback, battle stories, advice, code, (failing) tests..
http://hibernate.org/
Top Related