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.

 

@Entity:

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

Eg:


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

@Id
@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.

logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.level.org.hibernate.type=TRACE

406 total views, 4 views today

About Mirthbees 677 Articles
Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in

Be the first to comment

Leave a Reply

Your email address will not be published.


*


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