MENU

Bean Validation: Validation based on multiple properties

by September 03, 2018
Quite often there is a need to apply validation to some of the bean's properties based on the state of the other properties of the same bean. Bean Validation allows to do this in several ways: usage of @AssertTrue on a getter method with validation logic usage of @ScriptAssert on a class level (Hibernate Validator specific) usage of custom constraint annotation on a class level To show each of the approaches let us consider two classes representing a library member and a book

JPA: a handy utility for Enums to combine with AttributeConverter

by November 06, 2017
As it was discussed in one of the previous posts JPA: Mapping Enums the right way, JPA 2.1 standardized AttributeConverters, which can, for example, be used to map Java enums in more controlled/predicted way. Let's quickly recap how it can be done. Using attribute converter to map java enum Let's assume we have a PhoneType enum and a simple entity that has this enum as a field. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below.

Java 9: What's new and interesting. Stream API improvements

by November 04, 2017
Stream API received a few nice additions with the Java 9. Both Stream interfaces as well as Collectors were updated. Let's start with the new collectors. To show these improvements we will use next classes: This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public class Student { private String firstName; private String

JPA: Ways to map many-to-many relationships with additional information

by October 26, 2017
In this post we will take a look at couple of ways how many-to-many relationships, which have additional information, can be mapped to entities using JPA. @ManyToMany annotation cannot be applied in such cases as it does not allow to map additional information from the join table. To show these approaches let's consider such small film rental database schema: We have three main entity tables - actor, film, and customer. Where film_to_actor as well as rental can be called join tables with additional information. Actors

Java 9: What's interesting and new. Collection API

by October 23, 2017
Java 9 brings a lot of big new features, tools and API enhancements. But somehow the most excitement comes from a few simple additions to collections at which we will look today. JEP 269: Convenience Factory Methods for Collections So why so many people are so excited about JEP 269? Creating a collection from a number of elements is actually an operation very frequently used in the code. How many times did you wrote something like: This file contains bidirectional Unicode text that

Code generators: Immutables 101

by August 14, 2017
In the next post of "Code generator" series we will will talk about Immutables. This annotation processor based code generator allows you to generate simple, safe and consistent value objects, without the need to write Builders, factory methods and so on... It is easy to use, it allows customization, and all you need to do is to define your model value object as interface or abstract class. To start using Immutables, all you need to do is to add it to your dependencies. For example

Code generators: MapStruct 101

by July 31, 2017
By this post I'll be starting a series of posts dedicated to different code generators, which makes our lives easier, and more fun. As we don't need to write boring code! Did you ever find yourself in a situation where you needed to copy data from one Java bean to another? Or maybe from an Entity to DTO? Does next code look familiar to you ? This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To

Instagram