Home » Tag Archives: JPA (page 4)

Tag Archives: JPA

Java: Using the specification pattern with JPA

java-interview-questions-answers

This article is an introduction to using the specification pattern in Java. We also will see how we can combine classic specifications with JPA Criteria queries to retrieve objects from a relational database. Within this post we will use the following Poll class as an example entity for creating specifications. It represents a poll that has a start and end ...

Read More »

JOOQ Facts: From JPA Annotations to JOOQ Table Mappings

jooq-2-logo

JOOQ is a neat framework, and it addresses a long issue I’ve had with advanced dynamic filtered queries. While Hibernate and JPA come with a useful Criteria API, which I’ve been using for quite some time, there are understandable limits to what you can do with those. For instance, you cannot go beyond simple SQL operations (e.g JOINS, NESTED SLECTS, ...

Read More »

Efficiently delete data with JPA and Hibernate

jboss-hibernate-logo

You may come to the situation where you have to perform a bulk deletion on a huge amount of datasets stored in a relational database. If you use JPA with Hibernate as underlying OR mapper, you might try to call the remove() method of the EntityManager in a way like the following:               public ...

Read More »

Spring-injected Beans in JPA EntityListeners

spring-interview-questions-answers

In Database Encryption Using JPA Listeners I discussed transparent encryption using a JPA EntityListener. This approach was transparent in the sense that the JPA Entity was (nearly) entirely unaware that encryption was occurring and the JPA EntityListener itself was unaware of the details. There was one big problem. EJB3 can inject resources into an EntityListener. Spring cannot. (N.B., I am ...

Read More »

JPA 2 | Fetch Joins and whether we should use them

java-interview-questions-answers

Introduction Recently I have been working with FETCH JOINS in JPA 2 to fetch the data eagerly from the Database and I learned quite a lot on why we should avoid using Fetch Joins in our day to day operations. Today’s blog post talks about my experience with Fetch and my learning (based mostly on the review comments I got ...

Read More »

Spring Data JPA Tutorial Part One: Configuration

spring-data-logo

Spring Data JPA is a project which aims both to simplify the creation of JPA based repositories and to reduce the amount of code needed to communicate with a database. I have been using it for a while at my work and in my personal hobby projects and it has indeed make things a lot more simpler and cleaner. Now ...

Read More »

How to use Reflection to Document your Data Model based on JPA Annotations

java-interview-questions-answers

So using JPA, Hiber­nate or EBeans is cool when you can just anno­tate your Java classes, but haven’t you always wished you could “gen­er­ate” doc­u­men­ta­tion of your data model from the code? Pulling infor­ma­tion of the the JPA / Hiber­nate  and other val­i­da­tion annotations? Assum­ing you have all those nice Anno­ta­tions in your beans:           @Entity @Table(name ...

Read More »

JPA 2 | Dynamic Queries Vs Named Queries

java-interview-questions-answers

JPA has its own Query language called JPQL. JPQL is very similar to SQL, with one major difference being that JPQL works with entities as defined in the application whereas SQL works with table and column names as defined in the database. JPA provides us with a variety of options when it comes to defining the JPA queries that will ...

Read More »

JPA 2 | EntityManagers, Transactions and everything around it

java-interview-questions-answers

Introduction One of the most confusing and unclear thing for me, as a Java Developer has been the mystery surrounding the Transaction Management in general and how JPA handles transaction management in particular. When does a transaction get started, when does it end, how entities are persisted, the persistence context and much more. Frameworks like Spring does not help in understanding the ...

Read More »

Mapping enums done right with @Convert in JPA 2.1

java-interview-questions-answers

If you ever worked with Java enums in JPA you are definitely aware of their limitations and traps. Using enum as a property of your @Entity is often very good choice, however JPA prior to 2.1 didn’t handle them very well. It gave you 2+1 choices: @Enumerated(EnumType.ORDINAL) (default) will map enum values using Enum.ordinal(). Basically first enumerated value will be ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close