Logging SQL as it’s executed is a fairly common desire when developing applications. Perhaps an ORM (such as Hibernate) is being used, and you want to see the actual SQL being executed. Or maybe you’re tracking down a performance problem and need to know if it’s in the application or the database, so step #1 … Continue reading Log4jdbc Spring Boot Starter
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 Boot, HTTPS required, and Elastic Beanstalk health checks
Spring Boot can be very easily configured to require HTTPS for all requests. In application.properties, simply set security.require-ssl=true And that works great – until you’re running the Spring Boot application on AWS Elastic Beanstalk with both HTTP and HTTPS listeners: In that case, Elastic Beanstalk’s health check is always done over HTTP. The configuration page … Continue reading Spring Boot, HTTPS required, and Elastic Beanstalk health checks
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
Issues using Ehcache with ARC as the Thymeleaf Cache
Ehcache’s ARC (Automatic Resource Control) is pretty great – it more or less automatically and optimally handles cache sizing/allocation. Using ARC, one can effectively say, “Here’s 2GB to allocate for caching – no more than that – manage the cache as best as possible.” Of course, more complex rules can also be done (on a … Continue reading Issues using Ehcache with ARC as the Thymeleaf Cache
Using Spring Cache as the Thymeleaf Cache
Thymeleaf includes caching that can be used to cache templates, fragments, messages, and expressions. The default implementation is an in-memory cache using standard Java collections. Wouldn’t it be nice to use the Spring Cache Abstraction instead? The advantages of such a setup include: Consistency – why have many separate caching implementations each configured in different … Continue reading Using Spring Cache as the Thymeleaf Cache
Improving Performance of Spring’s ShallowEtagHeaderFilter by 50%
I led the team developing a new web presence for Mackenzie Financial, an effort which involved performance testing (which is always a good practice). During that testing, I discovered that ShallowEtagHeaderFilter was generating a lot of garbage and a lot of time was being spent in it. That didn’t seem ideal so I dove in … Continue reading Improving Performance of Spring’s ShallowEtagHeaderFilter by 50%
Finding Bugs in IBM Java
The first rule of programming is “it’s always your fault.” Which, like all good rules, has some exceptions. After eliminating all other possibilities, I discovered a few issues in IBM’s Java Runtime (also known as the IBM J9 JVM) that were definitely not my fault. I consider the discovery of these issues to have been … Continue reading Finding Bugs in IBM Java