Browsed by
Category: Hibernate

Developers Repeated Mistakes

Developers Repeated Mistakes

In this post we are going to discuss about the repeated mistakes of developers during design/implementation/planning etc. This is just a sudden thought process, so this post will grow on my day to day experience and research wise only. Feel free to comment your repeated mistakes to add it to this master list. In Hibernate/Databases: While creating/planning a column for description, we forget to define the length of values it can hold or even forget to think such scenarios. So…

Read More Read More

102 total views, no views today

How to get JPA Project option in Eclipse STS ?

How to get JPA Project option in Eclipse STS ?

How to get JPA Project option in Eclipse STS ? By default JPA project option is not there when you check under New project in STS eclipse. To make it available install hibernate tools plugin(which is currently Jboss Tools)     Now you will be able to create the JPA Project,   Hope this helps!   708 total views, 2 views today

708 total views, 2 views today

GenerationType.IDENTITY vs GenerationType.SEQUENCE vs GenerationType.AUTO

GenerationType.IDENTITY vs GenerationType.SEQUENCE vs GenerationType.AUTO

GenerationType.IDENTITY vs GenerationType.SEQUENCE vs GenerationType.AUTO: In hibernate for the primary key/auto generated id value column we used to annotate @GeneratedValue with strategy as either of these, GenerationType.IDENTITY 2. GenerationType.SEQUENCE 3. GenerationType.AUTO   It is highly important to understand the difference between these generation types to make it fit in the right place. Suppose you have two tables namely store and coupon, store id is a primary key in store table and foreign key in coupon table. Store table: store_id |…

Read More Read More

739 total views, 1 views today

Understanding @JsonIgnore with JPA Hibernate

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 have category model with many to many mapping along with JsonIgnore annotation. So Here when I try to save coupon…

Read More Read More

791 total views, no views today

Understanding @Temporal and @JsonFormat in JPA Hibernate

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 hibernate, also it displays date and time, but I want to display only date in UI. So lets see what…

Read More Read More

869 total views, 1 views today

Spring Boot + EhCache Hibernate Working Example

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 because it took around 300ms only to load same number of records (1885 records). Also no query will run from…

Read More Read More

898 total views, no views today

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

[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 public class Coupon implements Serializable{ @ManyToMany private Set categoryList; }   and my Category Model is: @Entity public class Category…

Read More Read More

2,107 total views, no views today

How to avoid implicit cross joins in JPA ?

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 Long getStoreId() { return storeId; } }   Coupon Entity: I have created one empty and one long argument constructor…

Read More Read More

1,137 total views, no views today

Join two tables using Hibernate in Spring Boot Example

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 hibernate projections. How to create hibernate session from EntityManager? Use @PersistenceContext annotation to get entityManager object. EntityManager can be used…

Read More Read More

1,285 total views, 3 views today

Spring Boot Native Query Example

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 from store s”)   Sample @Repository Interface: Store is our object entity, where we need to perform find/findall/deleteby/count etc. @CrudRepository…

Read More Read More

791 total views, no views today