Home » Tag Archives: JPA

Tag Archives: JPA

Differences in JPA entity locking modes

java-interview-questions-answers

JPA provides essentially 2 types of locking mechanisms to help synchronize access to entities. Both mechanisms prevent a scenario, where 2 transactions overwrite data of each other without knowing it. By entity locking, we typically want to prevent following scenario with 2 parallel transactions: Adam’s transaction reads data X Barbara’s transaction reads data X Adam’s transaction modifies data X, and ...

Read More »

JPA Pitfalls / Mistakes

java-interview-questions-answers

From my experience, both in helping teams and conducting training, here are some pitfalls/mistakes I have encountered that caused some problems in Java-based systems that use JPA. Requiring a public no-arg constructor Always using bi-directional associations/relationships Using @OneToMany for collections that can become huge Requiring a Public No-arg Constructor Yes, a JPA @Entity requires a zero-arguments (or default no-args) constructor. ...

Read More »

A Working DeltaSpike Tutorial

java-interview-questions-answers

On a recent project, I was faced with an interesting problem: take a service method that was given a single object and reuse the same code in the context of a nightly process that would run independently of the application over thousands of the same type of object. It would have been ridiculous to try to maintain an identical process ...

Read More »

Pre Java EE 7 alternative to JPA 2.1 unsynchronized persistence context

java-interview-questions-answers

Unsynchronized persistence context in Java EE 7 JPA 2.1 introduced the concept of unsynchronized persistence context which allows fine grained control over flushing of the JPA Entity Manager i.e. by explicitly calling EntityManager#joinTransaction. Previously, this was defaulted to end of JTA transaction e.g. in a typical Stateless EJB, the entity manager would flush its state to the DB at the ...

Read More »

JPA in case of asynchronous processing

java-interview-questions-answers

Few years ago in Java world it was almost obvious that every “enterprise” class project needed JPA to communicate with database. JPA is a perfect example of “leaky abstraction” described by Joel Spolsky. Great and easy at the beginning but hard to tune and limiting at the end. Hacking and working directly with caches, flushes and native queries is a daily ...

Read More »

Integrating JPA Hibernate with OptaPlanner

optaplanner-logo

We’ve been improving the integration of OptaPlanner with the rest of JEE, so it’s easier to build end user applications that just work. Let’s take a look at the improved JPA Hibernate integration. The basics Both JPA Hibernate and OptaPlanner work on POJO’s (Plain Old Java Objects), so just add some JPA annotations on your domain objects to persist them ...

Read More »

WebSocket Client API in Java EE 7

java-interview-questions-answers

In this post, let’s explore the less talked about Web Socket Client API and how to leverage it within a Java EE 7 container itself. Web Socket Server API rules The server side API of JSR 356 (Web Socket API for Java) is most commonly used for building Web Socket endpoint implementations. More often than not, from a client perspective, ...

Read More »

Using JPA And CDI Beans With Camel on WildFly

jboss-wildfly-logo

I didn’t really plan for it, but with a conference free month, I had the chance to dig around a little more and show you even more of the Camel on WildFly magic, that the WildFly-Camel subsystem provides. The Business Background The demo is derived from one on JBoss Demo-Central by Christina Lin. She demonstrates the use of File and JDBC ...

Read More »

How To Stream/Serialize JPA Result As JAX-RS Response For Large Data

java-interview-questions-answers

There are times that retrieving a large data set through JPA is necessary (e.g. more than 1,000,000 records) and having them stuffed into a single instance of java.util.List is just risky (memory barrier). So, here’s a quick solution of how a JAX-RS REST resource end-point could still give us a timely Response without breaking the memory constrain through streaming or ...

Read More »

Custom Boolean User Type with Hibernate JPA

jboss-hibernate-logo

The ANSI SQL 1999 standard introduced a BOOLEAN data type (although unfortunately only as an optional feature). But to date it still isn’t implemented by most major database systems. As a consequence boolean columns are implemented in various ways. E.g., CHAR columns containing ‘Y’ or ‘N’, or using BIT columns. Subsequently, there is no way for JPA to provide a ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Advanced Java Guide
  • Java Design Patterns
  • JMeter Tutorial
  • Java 8 Features Tutorial
  • JUnit Tutorial
  • JSF Programming Cookbook
  • Java Concurrency Essentials