Posts

Showing posts from 2015

Message Bundle from DB - Part 1 (J2EE)

This is the first part of a post about message bundles. Having to work on applications requiring support for different languages I had the need to have a message bundle retrieving the translation from a DB. With a  DB was easier to update labels not correctly translated without the need of restarting the application. We are going to build a service providing the functionality to store and retrieve localized messages from a database. In the second part we will build the same with the Spring Framework. Source code: https://github.com/oivarc/j2ee-samples.git The source code you will find on the repository contains a bit more of what is showed here. There is also a simple page used for test that gives the possibility to add/edit the label in different languages. The code has been tested using NetBeans, Glassfish 4.1, JavaDB. It uses the EclipseLink for the JPA connection and PrimeFaces for the UI. Let's start introducing the database structure we will utilize to store the loca

Spring Data Repositories: Query by Specification

Working with Spring and Spring Data repositories I got the need to have flexible queries based on some of the property of an entity class that should be put in OR in the query if they were present. Instead of creating a query for each combination of properties, I used one of the facilities provided by Spring-Data: the query by Specification. Before going into the details some background information. What I am going to show is an example based on the JpaRepository using Hibernate as persistency layer. A full working example can be found here:  query-by-spec The trick is in the use of the Specification interface in combination with a JpaSpecificationExecutor. Let's start... First we define an entity with some properties: @Entity @Table(name = "person") public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = "name") private String name; @Column(name = "surname") private Strin