Hibernate: Dynamic Insert

While doing code-review I came across hibernate’s dynamic-insert property and found it really useful. dynamic-insert is a boolean attribute of class element as defined in hibernate-mapping-3.0.dtd. This is an optional attribute of the class element and if not defined explicitly defaults to false.

As the name says, setting this property to true makes insert query generated by hibernate dynamic i.e. it will include only non-null values of DTO in the prepared statement.

Let’s explore this with the help of an example, for which I’m using PostgreSQL 9 and Hibernate 5.1.0.
Continue reading “Hibernate: Dynamic Insert”