Upgrade to Pro — share decks privately, control downloads, hide ads and more …

New features of Hibernate 5 you didn’t know

Edson Yanaga
February 24, 2017

New features of Hibernate 5 you didn’t know

Everybody know Hibernate right? Perhaps don’t. JPA is so popular these days that many people think that Hibernate is just a JPA implementation. Wrong! Hibernate is a very powerful tool and is constantly innovating. Have you checked Hibernate recently? There are a lot of new features that you probably don’t know, but you should!

Join us on this session to see which are the new features provided on Hibernate 5 that you didn’t know, including: new Bootstrap API, Java 8 support, Generics and AutoCloseable, Bytecode Enhancement for lazy fields and collections. And wouldn’t be great if we could integrate ElasticSearch with Hibernate so that all changes are in sync? And what about using your domain objects in ElasticSearch queries? We got it all covered!

Edson Yanaga

February 24, 2017
Tweet

More Decks by Edson Yanaga

Other Decks in Technology

Transcript

  1. New Features of Hibernate 5 you didn’t know Edson Yanaga

    Director of Developer Experience @yanaga
  2. “The two most important days in your life are the

    day you are born and the day you find out why.” — Mark Twain
  3. StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder() .configure( "org/hibernate/example/MyCfg.xml" ) .build(); Metadata

    metadata = new MetadataSources( standardRegistry ) .addAnnotatedClass( MyEntity.class ) .addAnnotatedClassName( "org.hibernate.example.Customer" ) .addResource( "org/hibernate/example/Order.hbm.xml" ) .addResource( "org/hibernate/example/Product.orm.xml" ) .getMetadataBuilder() .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .build(); SessionFactory sessionFactory = metadata.getSessionFactoryBuilder() .applyBeanManager( getBeanManagerFromSomewhere() ) //CDI BeanManager to the SessionFactory being built .build();
  4. Java 8 • New types • Date and Time API

    • Java 5, 6 e 7 • Generics • AutoCloseable
  5. Date and Time • DATE: java.time.LocalDate • TIME: java.time.LocalTime, java.time.OffsetTime

    • TIMESTAMP: java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime and java.time.ZonedDateTime <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-java8</artifactId> <version>${hibernate.version}</version> </dependency>
  6. Generics and AutoCloseable • AutoCloseable resources: • Session/StatelesSession • SessionFactory

    • ScrollableResults try ( Session session = sessionFactory.openSession() ) { Address address = session.get(Address.class, id); return address.getCity(); }
  7. Bytecode Augmentation • Smarter change detection • Better Maven and

    Gradle support • Enhanced Dirty checking • Bidirectional relationship management
  8. Maven <plugin> <groupId>org.hibernate.orm.tooling</groupId> <artifactId>hibernate-enhance-maven-plugin</artifactId> <version>${currentHibernateVersion}</version> <executions> <execution> <configuration> <failOnError>true</failOnError> <enableLazyInitialization>true</enableLazyInitialization>

    <enableDirtyTracking>true</enableDirtyTracking> <enableAssociationManagement>true</enableAssociationManagement> </configuration> <goals> <goal>enhance</goal> </goals> </execution> </executions> </plugin>
  9. AttributeConverter • Enums without @Enumerated • Invoked on null values

    • Hibernate Envers integration • @ElementCollection • @MapKey
  10. JPA with NoSQL • MongoDB (Fongo) • Infinispan • Neo4j

    (remote and embedded) • Redis • EhCache • Cassandra • CouchDB