Browsed by
Category: Hibernate

Hibernate – Tutorials & Examples

Hibernate – Tutorials & Examples

Hibernate All Annotations – Tutorials & Examples @Embeddable: This annotation can be used for the joining tables, by default it is not even necessary with hibernate, but if your intermediate joining table needs any other addtional columns to be added, then you must have @Embeddable annotated class. Do remember, in spring boot projects, we used to create repository for all the entity files, so even though we have embedded class separately, we should not create repository classes for this.  …

Read More Read More

1,037 total views, 1 views today

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

836 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,   Could not find Database perspective in your eclipse ? ThenĀ  you may not have installed the below plugin, which could have caused database perspective issue in your eclipse….

Read More Read More

1,446 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

2,403 total views, 4 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

1,856 total views, 3 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

1,994 total views, 4 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

1,673 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

3,737 total views, 2 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

2,779 total views, 4 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

2,610 total views, 2 views today