Home » Tag Archives: JPA

Tag Archives: JPA

Access the EntityManager from Spring Data JPA

spring-interview-questions-answers

Spring Data JPA allows you to rapidly develop your data access layer through the use of Repository interfaces. Occasionally you will need to access the EntityManager from Spring Data JPA. This post shows you how to access the EntityManager. EntityManager The purpose of the EntityManager is to interact with the persistence context. The persistence context will then manage entity instances ...

Read More »

Understanding the first level JPA cache

java-interview-questions-answers

I can bet that every Java developer at least heard about L1 (aka EntityManager or Session) cache. But is your level of understanding it good enough? If you’re not sure, consider going through this post. At first, we need to know what the persistence context is. Following EntityManager JavaDoc we know, that: “A persistence context is a set of entity instances in which for ...

Read More »

Dealing with Java’s LocalDateTime in JPA

java-interview-questions-answers

A few days ago I ran into a problem while dealing with a LocalDateTime attribute in JPA. In this blog post I will try to create a sample problem to explain the issue, along with the solution that I used. Consider the following entity, which models an Employee of a certain company – @Entity @Getter @Setter public class Employee { @Id ...

Read More »

Spring Data with JPA and @NamedQueries

spring-interview-questions-answers

If you use Spring Data and @NamedQuery annotations at your JPA entity you can easily use them in a more convenient way using the spring data repository. On a previous blog we created a spring data project using spring boot and docker. We will use the pretty same project and enhance our repository’s functionality. We will implement a named query ...

Read More »

Reference by Identity in JPA

java-interview-questions-answers

In a previous post, I mentioned that I opted to reference other aggregates by their primary key, and not by type. I usually use this approach (a.k.a. disconnected domain model) when working with large or complex domain models. In this post, let me try to explain further how it can be done in JPA. Note that the resulting DDL scripts ...

Read More »

OpenMap Tutorial 5 – 3-tier GIS application

1. Introduction Welcome to the 5th tutorial of the OpenMap series of Tutorials.  OpenMap is a free open source Java GIS library. Here is a list of previous tutorials: In the first tutorial we created a basic OpenMap GIS application that displays a map with one shape layer, loaded from the filesystem, inside a JFrame. That tutorial was based on ...

Read More »

Using Stored Procedures With JPA, JDBC. Meh, Just Use jOOQ

The current edition of the Java magazine has an article about Big Data Best Practices for JDBC and JPA by Josh Juneau: http://www.javamagazine.mozaicreader.com/MayJune2016 The article shows how to use a stored procedure with JDBC (notice how resources aren’t closed, unfortunately. This is commonly forgotten, even in Java Magazine articles) // Using JDBC to call upon a database stored // procedure CallableStatement ...

Read More »

Spring boot and Spring data JPA integration

spring-interview-questions-answers

Nowadays spring and JPA integration has become a piece of cake thanks to Spring Boot and spring Data. I am gonna setup a postgresql server docker pull postgres #run the container docker run --name postgreslocal -e POSTGRES_PASSWORD=postgres -d postgres #get the ip docker inspect --format '{{ .NetworkSettings.IPAddress }}' postgreslocal #get the port docker inspect --format '{{ .NetworkSettings.Ports }}' postgreslocal Create ...

Read More »

Using JINQ with JPA and H2

java-interview-questions-answers

A few days ago I have read the interesting interview with Ming-Yee Iu about JINQ. JINQ is, like the name already suggests, the attempt to provide something similar to LINQ for Java. The basic idea is to close the semantic gap between object-oriented code that executes queries on a relational data model. The queries for the relational database model should be ...

Read More »