Tag Archives: Hibernate

Hibernate Fetch Lazy Child Entities with HQL and Native SQL

In one-to-many or many-to-many relationship, we often configure Hibernate to lazily fetch the children collection for performance reasons by reducing the database join operation and the amount of the data been pulled and transmitted from database to application. The application, … Continue reading

Posted in Database, Java | Tagged , , , , , , , , | Leave a comment

Cleanup Stale Hibernate Session in Tomcat

Problem: When Hibernate is configured to use thread based session management, a thread may get stuck (unable to unbind) with a closed session under certain condition, therefore all subsequent incoming HTTP calls assigned to such a thread would fail until … Continue reading

Posted in Database, Java | Tagged , , , , | Leave a comment

Open H2 UI When Debugging in Eclipse

This time it is about debugging the H2 embedded database, which is very similar to procedure used with the HSQLDB I posted earlier. Assuming that the hibernate.connection.url is set to jdbc:h2:mem:myDb, you can following similar steps as in my previous … Continue reading

Posted in Database, Java, Tool and Debug | Tagged , , , , | Leave a comment

Hibernate Formula Annotated Field Behaviors

When the @Formula annotation is used to create a virtual column (in object model but not in database), developers should be aware of some behaviors to avoid of any pitfalls. This post uses the source code here to demonstrate these … Continue reading

Posted in Database, Java | Tagged , , , | Leave a comment

Use Hibernate Query Language to Join Tables and Map Column Values to Java Objects

The following example creates a HQL statement with named parameters, executes the query then maps the query result back to Java objects. The two named parameters in the example are accountNumber and trackingId. The three selected columns are unitPrice, qty … Continue reading

Posted in Database, Java | Tagged , | Leave a comment

Query the In-memory HSQLDB When Integrated With Hibernate

HSQLDB in-memory database is often used with Hibernate for testing, prototyping and even in production environment. With Hibernate, you can perform powerful database operations either using the ORM based APIs, HSQL or native SQL. As a developer, sometimes you want … Continue reading

Posted in Database, Java, Programming, Tool and Debug | Tagged , , , | 1 Comment