Red Hat

In Relation To Vlad Mihalcea

In Relation To Vlad Mihalcea

Hibernate Community Newsletter 5/2016

Posted by    |       |    Tagged as Discussions Hibernate ORM

Welcome to the Hibernate community newsletter in which we share blog posts, forum and StackOverflow questions that are especially relevant to our users.


The new User Guide is online, and it’s now the default Hibernate reference documentation. We keep on improving it, and the next release will contain a chapter about Hibernate Spatial, a section about calling stored procedures, and an update to the Multi-tenancy chapter.

Sanne talked about Hibernate Search and Lucene at the London Lucene/Solr Meetup. I hope the recordings will be available soon.


Bozhidar Bozhanov wrote a step-by-step guide for integrating Hibernate, Spring, and Infinispan.

Dane Dennis, from JArchitect, analyzed the Hibernate Core API and concluded that Hibernate is a "good example of open source projects to learn from".

While running some tests on all major relational database systems, I bumped into a very interesting issue relating to MySQL metadata locking. The bottom line is that you a transaction should always end as otherwise locks might be held, therefore impacting other concurrent transactions.

The New Hibernate ORM User Guide

Posted by    |       |    Tagged as Discussions Hibernate ORM

Big news

We are glad to announce that the new Hibernate ORM User Guide has become the default Hibernate 5.1 reference documentation. This process was started last summer, and it was one of the primary goals of the Hibernate 5 project version.

What’s changed

Previously, all the documentation was written in DocBook, and we wanted to move away to a more human-friendly format. Thanks to Dan Allen and the Asciidoctor community, we now have a tool to write technical documentation where the actual content doesn’t get lost in a myriad of XML markup tags.

All the examples are embedded from unit tests which are, of course, available on GitHub. This way, we ensure that all code snippets are valid and relevant in the future as well (removing a deprecated class will trigger a test failure, and we can immediately update the broken example).

The previous documentation was featuring many XML-based examples which were no longer relevant for the vast majority of our users. Because it is very common to use Hibernate as a JPA provider, most examples are written according to the Java Persistence API specifications but, since Hibernate is more than a JPA provider, we also feature Hibernate-specific examples which cover use cases that are not supported by the JPA standard.

What’s to come

As previously stated, the User Guide is not finished yet. In the near future, we are going to enhance the following sections as well:

  • Hibernate support for calling stored procedures,

  • Migrating Hibernate Envers examples to unit tests,

  • Multi-tenancy examples,

  • A new section about Hibernate Spatial.

Enjoy reading it and we are looking forward to getting your feedback!

Hibernate Community Newsletter 4/2016

Posted by    |       |    Tagged as Discussions Hibernate ORM

Starting this year, we are hosting a series of articles focused on the Hibernate community. We share blog posts, forum and StackOverflow questions that are especially relevant to our users.


We are happy that Hibernate 5.1 is ready. The new User Guide still needs a few site-related changes in order to make the switch, so stay tuned!


Ondrej Mihályi made a summary of the differences in JPA entity locking modes.

Lorenzo Dee wrote an article about JPA pitfalls.

I wrote an article about enabling bytecode enhancement in Hibernate 5.

Hibernate Community Newsletter 3/2016

Posted by    |       |    Tagged as Discussions Hibernate ORM

Starting this year, we are hosting a series of articles focused on the Hibernate community. We share blog posts, forum and StackOverflow questions that are especially relevant to our users.


Eugen Paraschiv wrote a very detailed article about auditing entity changes, comparing JPA callback annotations with Hibernate Envers and Spring Data JPA Auditing.

The guys at Plumbr have raised awareness of how the MySQL JDBC driver handles database-generated warning messages. We created a JIRA issue for this, and we’re discussing various possibilities for handling it without affecting other database drivers which are more efficient in this regard.

I wrote an article about the AUTO flush mode handling strategies employed by the Hibernate implementation of the Java Persistence API and the Hibernate native API.

WildFly 10 has just been released with support for Hibernate 5.


Thorben Janssen recorded a video explaining the first-level cache.

Hibernate Community Newsletter 2/2016

Posted by    |       |    Tagged as Discussions Hibernate ORM

Starting this year, we are hosting a series of articles focused on the Hibernate community. We share blog posts, forum and StackOverflow questions that are especially relevant to our users.


A very interesting project is Apache Trafodion, which aims to build a transactional SQL engine on top of Hadoop. We’d like to thanks the Trafodion team for writing a Hibernate Dialect, therefore making it possible to access Hadoop from a Hibernate data access layer. Give it a try and let us know what you think.

Thorben Janssen wrote an article about calling native SQL queries from JPA.

Romain Manni-Bucau demonstrates how you can integrate JPA pagination with Java 8 Streams.

Michael J. Simons, who gave us the idea of writing the JPA test case templates, describes the EuregJUG site architecture which, along other open-source frameworks, makes use of Hibernate for accessing data.

JPA test case templates

Posted by    |       |    Tagged as Hibernate ORM

In the good spirit of open source, any Hibernate ORM issue should be accompanied by a replicating test case. The test case is a proof that the issue really exists and is reproducible.

To simplify the test case writing procedure, Hibernate provides a series of templates that you can just grab from GitHub. Thanks to these tests, the issue reporter can focus on the actual persistence-related problem since the templates take care of all the bootstrapping logic.

Previously, the test case templates were available only for the Hibernate native API, which was fine as long as you’re familiar with it. Because many projects use Hibernate as a JPA provider, it’s very convenient to offer a JPA bootstrap environment as well. And that’s what we did.

Next, I’m going to provide a step-by-step guide for writing a JPA-based Hibernate test case.

First, you need to either fork or download the hibernate-test-case-templates GitHub repository.

This repository has an orm folder containing two Maven modules:


To replicate issues for Hibernate 4.x


To replicate issues for Hibernate 5.x

Each module has three templates:

This one is a Hibernate native test case (you get access to the SessionFactory and you operate with a Session), but it requires you to manually bootstrap the Hibernate environment.

This is also a Hibernate native test case (you get access to the SessionFactory and you operate with a Session), but the bootstrapping is provided on your behalf.

This is the new template that needs to be used for replicating an issue using the Java Persistence API (you get access to the EntityManagerFactory and you operate with an EntityManager).

When replicating an issue with the Hibernate native API, the ORMUnitTestCase is usually preferred.

This post focuses on the newly added JPAUnitTestCase which looks like this:

public class JPAUnitTestCase {

    private EntityManagerFactory entityManagerFactory;

    public void init() {
        entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );

    public void destroy() {

    // Entities are auto-discovered, so just add them anywhere on class-path
    // Add your tests, using standard JUnit.
    public void hhh123Test() throws Exception {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        // Do stuff...

The EntityManagerFactory is created before every test case and destroyed afterwards. The test case logic goes inside the @Test Junit method.

You should name the test method after the Hibernate JIRA issue you are trying to replicate.

The EntityManagerFactory uses the templatePU Persistence Unit, which is located under src/test/resources/META-INF/persistence.xml. By default, this file looks like this:

<persistence xmlns=""

    <persistence-unit name="templatePU" transaction-type="RESOURCE_LOCAL">

        <description>Hibernate test case template Persistence Unit</description>


            <property name="hibernate.archive.autodetection" value="class, hbm"/>

            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1"/>
            <property name="hibernate.connection.username" value="sa"/>

            <property name="hibernate.connection.pool_size" value="5"/>

            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="" value="create-drop"/>

            <property name="hibernate.max_fetch_depth" value="5"/>

            <property name="hibernate.cache.region_prefix" value="hibernate.test"/>
            <property name="hibernate.cache.region.factory_class"

            <!--NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle-->
            <property name="hibernate.jdbc.batch_versioned_data" value="true"/>

            <property name="javax.persistence.validation.mode" value="NONE"/>
            <property name="hibernate.service.allow_crawling" value="false"/>
            <property name="" value="true"/>


The persistence.xml configuration file is already set up for bootstrapping Hibernate, offering a reasonable default environment. In case you want to provide a different configuration, like using JTA with a stand-alone Transaction Manager, you’ll have to change the default configuration.

All entities are auto-discovered, so you can place them anywhere on classpath. In this example, we are going to use the following entity:

public class Event {

    private Long id;

    @Temporal(TemporalType.TIMESTAMP )
    private Date createdOn;

    public Event() {

    public Event(Date createdOn) {
        this.createdOn = createdOn;

    public Long getId() {
        return id;

    public Date getCreatedOn() {
        return createdOn;

Now, the persistence logic can be added to the JUnit test method:

public void hhh123Test() throws Exception {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Event event = new Event( new Date() );
    entityManager.persist( event );

    Event dbEvent = entityManager.createQuery(
            "select e " +
            "from Event e", Event.class)
    assertEquals(event.getCreatedOn(), dbEvent.getCreatedOn());


That’s it! You can now provide a Hibernate test case using the standard Java Persistence API.

Hibernate Community Newsletter 1/2016

Posted by    |       |    Tagged as Discussions Hibernate ORM

Happy New Year, everyone!

Starting this year, we are going to host a series of articles focused on the Hibernate community. We are going to share blog posts, forum and StackOverflow questions, that are especially relevant to our users.


Thorben Janssen, who regularly writes about JPA and Hibernate topics, has summarized the most typical logging configurations in a Hibernate Logging Guide.

For our Portuguese readers, Rafael Ponte has written a very interesting article about bidirectional relationships and the caveats of not properly synchronizing both ends of a bidirectional association.

One topic, I always wanted to investigate in great details, is about the aggressive connection release behavior employed for JTA transactions. For high-performance data access platforms, it’s worth checking if the Java EE application server can operate successfully even without aggressive connection release.

Building the Hibernate blog with Docker on Windows

Posted by    |       |    Tagged as Discussions

For my first post, I’d like to share the experience of running the blog on my Windows machine.

All the blog content is available on GitHub, and you can practically run the whole site on your local environment.

The Hibernate blog is built with awestruct from Asciidoctor files, and getting all the Ruby gems in place is definite not a walk in the park. To make matters worse, I’m running a Windows machine and all these Ruby gems are tightly coupled to Linux libraries, as I discovered after several failed attempts with the 64 bits Ruby 2.2.4 or the 32 bits Ruby 1.9.3.

Luckily, there is a dockerfile available, so building a Docker image and run it in a dedicated container can tackle the Ruby gem hell. Building the Docker image was fine, but running it was a three hours hackathon for both Emmanuel and I.

Docker images are immutable and all changes are wiped out once the container is terminated. Instead, we want the GitHub repository to be mirrored in the Docker container, so all changes are persisted even after shutting down the docker machine. This process can be done by mounting a host folder into the Docker container, which can happen upon running the Docker image. In our case, the mounted directory is the GitHub repository that’s mirrored inside the currently running Docker container.

Once the image is built, we need to run this command from within the GitHub repository folder:

docker run -t -i -p 4242:4242 -v `pwd`:/home/dev/ hibernate/

This doesn’t work on Windows because Docker needs the OS paths to be prefixed with another slash.

So this command must be changed to:

docker run -t -i -p 4242:4242 -v '/'`pwd`:/home/dev/ hibernate/

After running it, the mounted folder was just empty. We noticed that without the GitHub folder mounting part the Docker image could run properly, so the mounting process was the culprit.

After all sorts of hacks, Emmanuel had the idea of checking the Virtual Box Shared Folders, and, by default, only the C:\Users directory is being shared. No wonder it was not working all along.

All my repositories being on D:\, we thought that adding a new shared path would fix this issue. Well, it didn’t.

Docker must mount these Virtual Box shared folders too, but it only does so for C:\Users. There’s a GitHub issue detailing this behavior, which you can watch if you are interested in this feature.

After moving the checkout GitHub repository to /c/Users/Vlad/GitHub/, it all worked fine.

back to top