Understanding @JsonIgnore with JPA Hibernate

Understanding @JsonIgnore with JPA Hibernate @JsonIgnore Ignores from serialization and deserialization to and from JSON. Which means if you are calling REST API from anywhere then your attribute will not be present in JSON request/responses. But it will be persisted by JPA persistence.   I have Coupon and Category Model with Many to Many mapping: Here in coupon model I

175 total views, no views today

» Read more

Understanding @Temporal and @JsonFormat in JPA Hibernate

Understanding @Temporal and @JsonFormat in JPA Hibernate Many of us prefer to use varchar even for date fields due to difficulty of date related db operations. But it is strongly not recommended to use varchar for date fields and highly advicable to use datetime or timestamp in MySQL. Today we are going to see how to use datetime field with

145 total views, no views today

» Read more

Spring Boot + EhCache Hibernate Working Example

Spring Boot + Ehcache Hibernate Working Example: When I was trying to populate JSON records in my angular app (just 1885 records only), it took around 11 seconds and in angular side I am just populating in the datatable. So I thought to implement ehcache with spring boot to make it faster. After implementing that successfully I am really surprised

183 total views, 2 views today

» Read more

[Resolved] Illegal attempt to dereference path source [null.categoryList] of basic type

[Resolved] Illegal attempt to dereference path source [null.categoryList] of basic type This issue may happen for various use cases, I have explianed my usecase with the explantion, hope it helps someone.   Issue code: Expression catInExp = couponRoot.get(“categoryList”).get(“categoryName”); Predicate categoryInPredicate = catInExp.in(tempCategoryNamesSelected); allPredicates.add(categoryInPredicate);   Code Fixed: Expression catInExp = couponRoot.join(“categoryList”).get(“categoryName”); Predicate categoryInPredicate = catInExp.in(tempCategoryNamesSelected); allPredicates.add(categoryInPredicate);   My Coupon Model: @Entity

112 total views, no views today

» Read more

How to avoid implicit cross joins in JPA ?

How to avoid implicit cross joins in JPA ? When you join two tables and trying to select (column select) from the child table then you will come across this implicit cross join issues. For example we have two entities namely store, coupon and mapping follows, Store Entity: @Entity public class Store { @OneToMany(mappedBy = “store”) private List couponList; public

218 total views, no views today

» Read more

Join two tables using Hibernate in Spring Boot Example

Join two tables using Hibernate in Spring Boot Example: Many enterprise applications whichever using hibernate uses sql queries only for joins still and uses hibernate only for save/update operations. Today we are going to see how to use hibernate to join two tables. We are going to see how to get count(*) using hibernate along with group by function in

254 total views, 1 views today

» Read more

Spring Boot Native Query Example

Spring Boot Native Query Example: In Spring boot, database operations can be performed by implementing CrudRepository<Object, Long> in our @Repository interface. Here¬†Object is our entity class. @Query Annotation: We can execute nativeQueries using @Query annotation. Need to make the nativeQuery boolean to true and provide the native query to value parameter for @Query annotation.   Syntax: @Query(nativeQuery=true, value=”select s.store_name, s.store_url

178 total views, no views today

» Read more

JPA Predicate criteriabuilder example for beginners

JPA Predicate criteriabuilder example for beginners Predicate is an interface which extends Expression and can be used for conjunction or disjunction of restrictions.   Syntax to create a predicate: Predicate someCondition = criteriaBuilder.equal(affiliateUrlRoot.get(“shop_home_url”), “mirthbees”);     criteriaBuilder is a CriteriaBuilder, which can be created like this,   @PersistenceContext private EntityManager entityManager; CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); affiliateUrlRoot is the root of

184 total views, 1 views today

» Read more

Spring Boot with CriteriaBuilder for Dynamic Search Queries

Spring Boot with CriteriaBuilder for Dynamic Search Queries: Spring Boot with CriteriaBuilder for Dynamic Search Queries: When you are developing an enterprise application, you have to provide a search option dynamically with “and” condition. Our grand father way to do is using stringbuilder to construct the query in java and return the result. But hibernate has provided criteria for the

201 total views, no views today

» Read more

[Solved] The type CriteriaQuery is not generic;

[Solved] The type CriteriaQuery is not generic; It is because of the incorrect import. CriteriaQuery is available in both hibernate and persistence package. We have to import from persistence package in order to use criteriabuilder. CriteriaQuery should be imported from import javax.persistence.criteria.CriteriaQuery;   not from import org.hibernate.criterion.CriteriaQuery;   Sample snippet: @PersistenceContextprivate EntityManager em; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<AffiliateUrl> cq =

128 total views, no views today

» Read more
1 2 3