Home » Tag Archives: JBoss Hibernate (page 7)

Tag Archives: JBoss Hibernate

Hibernate Facts: Always check Criteria API SQL queries

java-interview-questions-answers

Criteria API is very useful for dynamically building queries, but that’s the only use case where I’d use it. Whenever you have an UI with N filters that may arrive in any M combinations, it makes sense to have an API to construct queries dynamically, since concatenating strings is always a path I’m running away from. The question is, are ...

Read More »

Hibernate Facts: Integration testing strategies

jboss-hibernate-logo

I like Integration Testing, it’s a good way to check what SQL queries Hibernate generates behind-scenes. But Integration Tests require a running database server, and this is the first choice you have to make. 1. Using a production-like local database server for Integration Testing For a production environment I always prefer using incremental DDL scripts, since I can always know ...

Read More »

ID Lists Aren’t the Best Solution for the N+1 Problem

jboss-hibernate-logo

In their eternal attempts to circumvent the N+1 problem, Hibernate users often resort to IN predicates with ID lists. In this post, we’ll see how those users might just be replacing a horrible thing with a bad one, which is better but not yet good. Here’s why: The N+1 Problem The N+1 problem is a well understood issue, documented in ...

Read More »

Hibernate Facts: Equals and HashCode

jboss-hibernate-logo

Every Java object inherits the equals and hashCode methods, yet they are useful only for Value objects, being of no use for stateless behavior oriented objects. While comparing references using the “==” operator is straight forward, for object equality things are a little bit more complicated. Since you are responsible for telling what equality means for a particular object type, ...

Read More »

Hibernate Facts: Multi level fetching

jboss-hibernate-logo

It’s quite common to retrieve a root entity along with its children associations on multiple levels. In our example we need to load a Forest with its Trees and Branches and Leaves, and we will try to see have Hibernate behaves for three collection types: Sets, Indexed Lists, and Bags. This is how our class hierarchy looks like:     ...

Read More »

Hibernate Facts: Knowing flush operations order matters

jboss-hibernate-logo

Hibernate shifts the developer mindset from thinking SQL into thinking object state transitions. According to Hibernate Docs entity may be in one of the following states:                   new/transient: the entity is not associated to a persistence context, be it a newly created object the database doesn’t know anything about. persistent: the entity ...

Read More »

Hibernate Facts: The importance of fetch strategy

jboss-hibernate-logo

When it comes to working with an ORM tool, everybody acknowledges the importance of database design and Entity-to-Table mapping. These aspects get a lot of attention, while things like fetching strategy might be simply put-off. In my opinion, the entity fetching strategy shouldn’t ever be separated from the entity mapping design, since it might affect the overall application performance, unless ...

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 »

Hibernate Facts: Favoring bidirectional Set(s) vs List(s)

jboss-hibernate-logo

Hibernate is a great ORM tool, and it eases development considerably, but it has a lot of gotchas you must be aware of if you want to use it properly. On medium to large projects it’s very common to have bidirectional parent-child associations, which allow us to navigate both ends of a given relationship. When it comes to controlling the ...

Read More »

Natural Ids in Hibernate

jboss-hibernate-logo

A natural id is a property or a set of properties that would identify an entity uniquely. We can have at-most one natural id defined for an entity. When Hibernate sees natural-id tag in an entity mapping file, it automatically creates unique and not-null constraints on the properties constituting natural-id. First, let us look at examples of simple and composite ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.