JDriven Blog

Hibernate and Collections

Posted on by  
Ronald Koster

When adding/removing entities to/from a collection in Hibernate one may easily run into annoying TransientObjectException or TransientPropertyValueException exceptions. This blog uses a simple example to describes how to avoid these issues.

Continue reading →

Room to fail

Posted on by  
Erik Pronk

Last weekend I was in London with my daughter for a lovely couple of days and a Bon Jovi concert. We were sitting together in a Costa Coffee when a young couple sat down across us. At first I did not really notice them, only that there were these odd little sounds that kept repeating. Then it clicked, when they stood up and started filming their TikTok dance, the sound turned up loud, with eyes only for the phone that had been carefully positioned for the perfect shot.

Continue reading →

Hibernate with Business Keys

Posted on by  
Ronald Koster

A common practice with Hibernate is to give each entity an id field to store its primary key. This field is generally managed by Hibernate. When the entity has not been saved yet, the field is null, which is also how Hibernate detects the object has not been saved yet. Once it is saved, Hibernate sets the value of the id to the generated value. Since the value of the id field changes, it is not suited to base your equals and hashCode methods on. Which is a bit counter-intuitive, because it corresponds to the primary key in the database. The solution is to use Business Keys.

Continue reading →

Datetime formats and types in APIs and databases

Posted on by  
Ronald Koster

How to represent datetimes in APIs, the code, and the database is always tricky. Most people I have worked with struggled with this. The main mistake is omitting the time zone based on the false assumption that defaults are uniform across systems. They are not. As a result timestamps carried across systems get weird time jumps. This blog gives some rules to avoid these mistakes and gives a clean set up.

Continue reading →

Null Safe(r) Java with NullAway

Posted on by  
Jorrit van der Ven

After working on Kotlin projects for over seven years, I recently started on a Java project again. One of the things I missed most was the fact that Kotlin explicitly supports nullability as part of its type system. Within the first day I ran into a NullPointerException. Luckily, we can now add compile-time null checks to Java as well, making Java null safe(r)!

Continue reading →

Did I Map Everything?

Posted on by  
Tundzaj Barov

When migrating database schemas, you rarely get clean, predictable data. Legacy databases often have cryptic column names, partially backfilled fields, nullable values, or columns that are completely empty. That’s why you write custom Java JDBC mappers in the first place: to explicitly control how legacy database columns map to your target Java objects, rather than relying on automatic mapping that may not handle these inconsistencies correctly. But there’s a catch: standard unit tests can pass even when you completely forget to map a field. Because null == null, a missing mapping line looks identical to a column that is legitimately empty in your database.

Continue reading →

Pondering AI - and AIthics

Posted on by  
Justus Brugman

There is no shortage of discussion about AI, and LLMs in particular. This is my personal take on the debate: the claims I question, the concerns I share, and the questions I am still working through. Wild claims abound, from “Soon, we won’t need developers anymore” and “AI is taking over the world” to “LLMs are a dead end,” “LLMs are bad for the environment,” “LLMs commit plagiarism,” and “LLMs are unethical.” And the list goes on.

Continue reading →

Mastering Maven: Failing Faster With Failing Tests

Posted on by  
Hubert Klein Ikkink

Maven uses the Surefire plugin to run unit tests and the Failsafe plugin to run integration tests. The default behaviour of Maven is to run all tests and show a summary at the end. The summary shows how many tests have run and how many failures, errors and skipped tests happened. So every time when you run mvn test or mvn verify all tests will be executed, even when tests are failing. You can speed up your build by stop running tests once a test fails. You must use the Java system properties surefire.skipAfterFailureCount and failsafe.skipAfterFailureCount to make sure Maven will skip running any tests after a test failure has occurred. You can specify a number with the parameter to set how many tests should fail before other tests are skipped. It is possible use these parameters in the plugin configuration in your pom.xml as well.

Continue reading →

shadow-left