Version Controlling Database Schemas and Data with Liquibase

Version controlling database schemas facilitates repeatable deployments and consistent environments. The alternative is have a human manually perform database modifications; since humans are human, we tend to make mistakes especially when performing repetitive tasks, and our time is also very expensive compared to that of machines, so automating database schema changes is superior approach. More … Continue reading Version Controlling Database Schemas and Data with Liquibase

Working around HHH-9663: Orphan removal does not work for OneToOne relations

HHH-9663 means that orphan removal doesn’t work for OneToOne relationships. For example, given File and FileContent as below (taken from the bug report): package pl.comit.orm.model; import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.Id;import javax.persistence.OneToOne; @Entitypublic class File {  private int id;  private FileContent content;  @Id public int getId() { return id; }  public void setId(int id) { this.id = id; }  … Continue reading Working around HHH-9663: Orphan removal does not work for OneToOne relations

Spring Cache Abstraction as a Hibernate Cache Provider

Many of the projects I’ve worked on over my career have leveraged a Spring/Hibernate stack. Over that time, the Spring/Hibernate integration has greatly improved making the once tedious and repetitive chore of setting up a new project (and maintaining an existing one through upgrades, expansion, and refactoring) far simpler. Now it’s as simple as going … Continue reading Spring Cache Abstraction as a Hibernate Cache Provider

Spring ID to Entity Conversion

When using Spring with Hibernate or JPA, it can be very convenient to use objects as method parameters and automatically convert primary keys to those objects. For example: @RequestMapping(value = "/person/{personId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)@ResponseBodypublic PersonDto getById(@PathVariable Person person) { return person;} instead of: @RequestMapping(value = "/person/{personId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)@ResponseBodypublic … Continue reading Spring ID to Entity Conversion

Issues using Ehcache with ARC as the Hibernate Cache

When using Ehcache’s ARC (Automatic Resource Control) on a cache acting as the Hibernate cache, these kinds of warning will likely appear: WARN [pool-1-thread-1] [ehcache.pool.impl.DefaultSizeOfEngine] sizeOf The configured limit of 100 object references was reached while attempting to calculate the size of the object graph. This can be avoided by adding stop points with @IgnoreSizeOf … Continue reading Issues using Ehcache with ARC as the Hibernate Cache

EhCache implementation of OpenJPA caching

I usually use Hibernate, which supports a number of caching implementations (such as EhCache, oscache, JBoss, etc). My most recent project had a dependency on a product which has a dependency on OpenJPA, and OpenJPA only has it’s own built in implementations of a query cache and a data cache. I like to have one … Continue reading EhCache implementation of OpenJPA caching