Blog Archives

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.… Read more ...



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 ...

Tags:

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 ...

Tags:

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

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.… Read more ...



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… Read more ...



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 ...



10: Spring, JavaConfig (i.e @Configuration), JPA & Hibernate by example

Example #1 Wiring JDBC Datasource

Read more ...


11: Hibernate dependency jars and plugins

Here is a sample maven pom.xml snippets containing the dependency jars. 

Read more ...


12: Hibernate custom data type : Blob type example

There are times you want to define a custom data type in Hibernate. Here is an example of using a custom ImageType defined as a Blob databse type to store images, excel files, etc.

Step 1: Define the custom Hibernate data type “ImageTpe” as shown below.… Read more ...



8 Hibernate interview Q&As

FAQ Hibernate interview questions & answers are covered below.

Q1. What is an Object-to-Relational Mapping (i.e. ORM) tool?
A1. There are several ways to persist data to a database from your Java applications.

1) Direct JDBC SQL statements for the CRUD (Create, Read, Update, and Delete) operations.… Read more ...

Tags: , ,

Hibernate First & second level cache interview Q&As

Q. What is a first-level cache in Hibernate? A. First-level cache always is associated with a “Session” object. Hibernate uses this cache by default. You can’t turn it off. Hibernate caches the SQL statements like insert, update, delete, etc in the first-level cache.… Read more ...



Q08 – Q15 Hibernate interview Q&As

Extends 15+ Hibernate interview questions & answers – Q1 – Q7. Hibernate interview questions & answers with diagrams & code snippets to not only prepare for the job interviews, but also to easily grasp the concepts Q9. Explain hibernate object states?… Read more ...



Don't be overwhelmed by the number of Q&As & tech stacks as nobody knows everything, and often key Q&As at the right moment makes a difference.

500+ Java Interview FAQs

Java & Big Data Tutorials

Top