Java EE: Setting up and Testing Form-Based JDBC Authentication with Arquillian and Maven

Especially when it comes to testing, setting up a decent environment for a secured Java EE web application isn’t always an easy thing to do. In the following tutorial I’d like to demonstrate how to create a secured web application using form-based authentication and a JDBC realm to fetch users and roles and how to run the application in an embedded container for testing and development. Additionally I’d like to show how to write and run integration tests to verify the security setup using a setup of Maven, Embedded GlassFish, Arquillian, jUnit and rest-assured. ...

December 21, 2014 · 14 min · 2822 words · Micha Kops

Java Persistence API: Controlling the Second-Level-Cache

Using the Java Persistence API and a decent persistence provider allows us to configure and fine-tune when and how the second level cache is used in our application. In the following short examples, we’re going to demonstrate those features written as JUnit test cases and running on a H2 in-memory database. Figure 1. Persistence Unit Configuration Setup First of all we need some basic setup to run the following examples .. we need to select a JPA persistence provider and database, create a persistence-unit configuration and an environment to run tests on an in-memory database. ...

April 21, 2014 · 7 min · 1417 words · Micha Kops

Creating elegant, typesafe Queries for JPA, mongoDB Morphia and Lucene using Querydsl

Querydsl is a framework that allows us to create elegant, type-safe queries for a variety of different data-sources like Java Persistence API (JPA) entities, Java Data Objects (JDO), mongoDB with Morphia, SQL, Hibernate Search up to Lucene. In the following tutorial we’re implementing example queries for different environments – Java Persistence API compared with a JPQL and a criteria API query, mongoDB with Morphia and last but not least for Lucene. ...

February 13, 2014 · 9 min · 1879 words · Micha Kops

Creating slim Database Projections using JPA2 Constructor Expressions

One common question that you may encounter one day when using object-relational-mapping in your application is how to slim down data that you’re retrieving from the persistence layer down to a specific subset for your use-case in an efficient manner and without using complex additional mapping frameworks. In some situations you might declare lazy loaded fields but another approach that I’d like to share with you here are JPA2 constructor expressions. ...

April 14, 2013 · 9 min · 1744 words · Micha Kops

Creating a sample Java EE 6 Blog Application with JPA, EJB, CDI, JSF and Primefaces on GlassFish

Java EE 6 is out and it indeed offers an interesting stack of technologies. So in today’s tutorial we are going to build a small sample web application that builds on this stack using Enterprise JavaBeans, Java Persistence API, Bean Validation, CDI and finally Java Server Faces and PrimeFaces. The application we’re going to develop is a simple blog app that allows us to create new articles, list them and – finally delete them. We’re also covering some additional topics like JSF navigation, i18n, Ajax-enabled components and the deployment on the GlassFish application server. ...

February 8, 2011 · 17 min · 3575 words · Micha Kops

Object-relational Mapping using Java Persistence API JPA 2

Today we’re going to take a look at the world of object-relational Mapping and how it is done using the Java Persistence API by creating some basic examples, mapping some relations and querying objects using JPQL or the Criteria API.. Prerequisites Java 6 JDK Maven >= 2 If you’d like to take a look behind the scenes e.g. how entities are mapped in your database you could install a RDBMS of your choice .. or just use Derby/JavaDB that is bundled with the JDK 6 ...

October 11, 2010 · 13 min · 2668 words · Micha Kops