Tags
Authors
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
We used to be very conservative on the constraints included in Hibernate Validator but we changed this policy recently and we would like to have more constraints built-in.
Of course, we won’t accept everything: the proposed constraints needs to be of general usage and well defined but the idea is to have more features in Hibernate Validator out of the box.
This post will be useful to those who have some interesting custom Bean Validation constraints and want to share them with the community.
[ ... ]
One of the most exciting features in Java 9 are modular runtime images. Using the new jlink utility, you can create customized distributions which contain your app, its dependencies and just the JDK modules which it needs. For instance, a simple service based on the Undertow web server can be packaged into an image of just 25 MB, batteries included.
While that’s pretty cool already, it gets even nicer, as jlink provides a plug-in mechanism which allows to fine-tune the contents modular runtime images as they are created. There’s a set of jlink plug-ins coming with the JDK, e.g. for compressing image contents or removing debug symbols. But many more use cases may benefit from this API, for instance one could imagine plug-ins for removing un-used code or for performing byte code instrumentation of JPA entities. In the following, we’ll create a plug-in for adding an annotation index to the created image. At runtime, this index can then be used to discover annotations very efficiently, i.e. without loading classes and using reflection.
Sound great?
For sure it does, there’s just one catch: the jlink plug-in API is not a supported part of the JDK as of Java 9.
In fact, its packages are not even exported from the jdk.jlink
module.
This means some tricks are required to create custom plug-ins and run the jlink tool with these plug-ins enabled.
The API may change in future Java versions, so any custom plug-in may break.
Nevertheless it’s definitely worth to explore the API and see what it can do. It’s my hope that it’ll be promoted to a public API eventually.
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
Without doubt, the module system (JPMS) is the most prominent feature of Java 9. But there are many other useful additions to the JDK, which have not been discussed as widely yet.
One of them is the new ToolProvider
SPI, which defines a uniform way to invoke all the tools coming with the JDK (e.g. jar
, jlink
etc.) in a programmatic way.
E.g. imagine you’d like to create a JAR archive from within your Java application.
Before Java 9, you had two options to do so:
-
Start a separate process to run the
jar
binary -
Find out which classes are used by the
jar
command internally and invoke them directly
Neither option is ideal.
The former incurs some overhead for forking an OS level process and it requires a bit of coding to locate the binary to execute in the Java home directory and to correctly capture any output of the forked process.
The second option doesn’t come with the disadvantages of forking a new process, but it requires knowledge about the implementation of the tool to execute.
So for instance in the case of the jar
command, you’d have to know that java.util.jar.JarOutputStream
is used to produce JAR files.
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.
As you may know, Bean Validation 2.0 has been released a couple of months ago and Hibernate Validator 6.0 is its reference implementation.
Hibernate Validator is not the only Bean Validation implementation out there, we have one (friendly) competitor called Apache BVal.
Apache BVal has not caught up with Bean Validation 2.0 yet but, as the last benchmark in the Bean Validation field is dated from 2010 (remember "Machete don’t text"?), I thought it was high time to revisit this benchmark and get some fresh numbers.
Especially with all the optimization work we made for 6.0.
Welcome to the Hibernate community newsletter in which we share blog posts, forum, and StackOverflow questions that are especially relevant to our users.