Blog Archives
1 2

02: Understanding Hibernate proxy objects and avoiding potential pitfalls

Q. How does hibernate support lazy loading? A. Hibernate uses a proxy object to support lazy loading. Basically as soon as you reference a child or lookup object via the accessor/getter methods, if the linked entity is not in the session cache (i.e. the first-level cache), … Read more ›...

Members Only Content
Log In Register Free Q&As


03: Identifying and fixing NonUniqueObjectException in Hibernate

NonUniqueObjectException is thrown when there is an object already associated with the session with the same id (primary key) (i.e. a duplicate). It is important to understand the concept of a “detached” object in Hibernate. This is one of the most common errors, understanding why and when this error is thrown will save you time in identifying and fixing this issue.

Read more ›



04: Identifying and fixing LazyInitializationException in Hibernate

LazyInitializationException is thrown when an object becomes detached, and if you try to access associated (i.e. proxied) object(s) of a detached object.

Q. What is a detached object in Hibernate?

When you close an individual Hibernate Session, the persistent objects you are working with are detached.

Read more ›



05: Debugging Hibernate & handling 4 common issues

#1. Enable Logging in your log4j.xml, log4j.properties, or myapp-logback.xml

In the log4j.properties file, you can enable Hibernate SQL logging as shown below

or in your log4j.xml or myapp-logback.xml as

You can then check your logs for the SQLs executed and the parameters passed. The example below shows 3 parameters passed to an update query

#2.

Read more ›



07: Hibernate mistakes – accessing objects outside of a transaction

Hibernate does require the same EntityManager to be available in order to lazily load objects. If you have no EntityManager, then you have no knowledge of the datastore. Once the transaction is committed the objects become detached, and you can’t lazy load detached objects. So, you need to lazily load...

Members Only Content
Log In Register Free Q&As


08: Hibernate automatic dirty checking of persistent objects and handling detached objects

Q1. What do you understand by automatic dirty checking in Hibernate? A1. Dirty checking is a feature of hibernate that saves time and effort to update the database when states of objects are modified inside a transaction. All persistent objects are monitored by hibernate.It detects which objects have been modified...

Members Only Content
Log In Register Free Q&As


09: Hibernate entities with auditable, soft delete & optimistic locking fields

There are certain generic columns that database tables have like Auto generated identity columns. Auditing columns like createdDtTm, createdBy, modifiedDtTm, and modifiedBy. Soft delete or logical delete flags like inactive ‘Y’ or ‘N’. Optimistic locking detection based on columns like Timestamp or version number. … Read more ›...

Members Only Content
Log In Register Free Q&As


1 2

Java FAQs to Fast-track & Go places

Big Data Engineer FAQs

Java Interview Q&As

Note that some posts belong to multiple categories.
Top