They are two ways to execute sql statements as batch in hibernate, which are 1) Work 2) ReturningWork This approach is useful when we want to perform batch operations directly on the database instead of indirectly through hibernate. First we will implement the Work interface as shown below JdbcWork class JdbcWork implements Work { private…… Continue reading Executing sql statements as a batch through hibernate
Category: Hibernate
Intercepting hibernate CRUD operations
This post explains how to intercept hibernate create, read, update and delete operations, so that we can add our own logic that has to be performaned before CRUD operations. The different use case where we need to intercept these hibernate operations are as follows 1) Every entity in the applications has common fields for example…… Continue reading Intercepting hibernate CRUD operations
Getting mapped class meta data
This post explains how to get hibernate related meta data information of a mapped class. Class package model; public class Series { private Integer id; private String name; private String description; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public…… Continue reading Getting mapped class meta data
Loading multiple instances by list of entity ids
From hibernate 5.1 we can load multiple instances of same class type in one shot by using the list of ids. The below code gives an example of this import java.util.List; import org.hibernate.MultiIdentifierLoadAccess; import org.hibernate.Session; import org.hibernate.SessionFactory; import model.Series; public class HibernateDemo { public static void main(String[] args) { SessionFactory sessionFactory = HibernateUtil.createSessionFactory(); Session session…… Continue reading Loading multiple instances by list of entity ids