Hibernate – Tutorials & Examples

Hibernate All Annotations – Tutorials & Examples


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.



This is the main annotation to link your class with your tables.


public class Coupon extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "coupon_id")
private Long couponId;

private String couponTitle;

@Column(columnDefinition = "varchar(3500)")
private String couponDesc;

// setters & getters for all the fields


  • coupon table will be mapped to this entity class
  • And maps all the three variables mentioned here to the respective columns in the coupon table.
  • if name attribute used inside @Column then the same name should be matched with your table column name.


For couponTitle no @column annotation and no name attribute, so by default, inside your entity class even if you don’t mention the @column it considers all the fields as columns and if the name attribute is not mentioned then it takes the default name, in this case coupon_title (as couponTitle) mentioned in camelcase.



How to see the actual values of the hibernate queries ?

Add the below entries to your spring boot application.properties file to see the actual values of the hibernate sql queries.





How to resolve “object references an unsaved transient instance – save the transient instance before flushing”?

In your hibernate savings, for any object if you have kept new Employee() (always in onetomany/manytoone mappings, we must give the database saved values only to that reference, we must not give new object() in those areas).

1,264 total views, 7 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.