Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?

Hibernate Cheat Sheet – DEV Community

## 📃 JPA Hibernate Annotations



@Entity :

  • This annotation is used to mark a category as an entity class.
  • This annotation is used to create a desk within the database.
@Entity
public class Model {
}
Enter fullscreen mode

Exit fullscreen mode




@Desk :

  • @Desk annotation is used to specify the main points of the desk that will likely be created within the database.
  • The identify attribute of the @Desk annotation is used to specify the identify of the desk.
@Entity
@Desk(identify = "manufacturers")
public class Model {
}
Enter fullscreen mode

Exit fullscreen mode




@Column :

  • @Column annotation is used to specify the main points of the column that will likely be created within the database.
  • The identify attribute of the @Column annotation is used to specify the identify of the column.


@Entity
@Desk(identify = "manufacturers")
public class Model {

    @Column(identify = "brandName")
    personal String brandName;
}
Enter fullscreen mode

Exit fullscreen mode




@id :

  • @id annotation is used to specify the first key of an entity.
  • The @id annotation is at all times used with the @GeneratedValue annotation.
@Entity
@Desk(identify = "manufacturers")
public class Model {
    @Id
    @Column(identify = "id")
    personal int id;

}
Enter fullscreen mode

Exit fullscreen mode




@ManyToOne :

  • @ManyToOne annotation is used to specify many to 1 relationship with one other entity.
@Entity
@Desk(identify = "manufacturers")
public class Model {
    @ManyToOne
    @JoinColumn(identify = "brandsDetails")
    personal BrandDetail brandDetail;
}
Enter fullscreen mode

Exit fullscreen mode




@OneToMany :

  • @OneToMany annotation is used to specify one to many relationship with one other entity.
  • The mappedBy attribute of the @OneToMany annotation is used to specify the property of the entity that’s the proprietor of the connection.
@Entity
@Desk(identify = "manufacturers")
public class Model {

    @OneToMany(mappedBy = "manufacturers", fetch = FetchType.EAGER)
    personal BrandDetail brandDetail;
}
Enter fullscreen mode

Exit fullscreen mode




@PrimaryKeyJoinColumn :

  • @PrimaryKeyJoinColumn annotation is used to specify the first key of the entity that’s the proprietor of the connection.
@Entity
@Desk(identify = "manufacturers")
public class Model {

    @PrimaryKeyJoinColumn
    personal int id;
}
Enter fullscreen mode

Exit fullscreen mode




@JoinColumn :

  • @JoinColumn annotation is used to specify the column that will likely be created within the database as a overseas key.
@Entity
@Desk(identify = "manufacturers")
public class Model {

    @JoinColumn(identify = "brandDetail")
    personal BrandDetail brandDetail;
}
Enter fullscreen mode

Exit fullscreen mode




@JoinTable ve @MapsId:

  • It’s used to specify the be part of desk that will likely be created within the database.
  • @JoinTable annotation is used to specify the be part of desk that will likely be created within the database.
  • @MapsId annotation is used to specify the first key of the entity that’s the proprietor of the connection.
@Entity
@Desk(identify = "manufacturers")
public class Model {

    @JoinTable(identify = "manufacturers")
    personal BrandDetail brandDetail;
}
Enter fullscreen mode

Exit fullscreen mode




@OneToOne:

  • @OneToOne annotation is used to specify one to 1 relationship with one other entity.
  • The mappedBy attribute of the @OneToOne annotation is used to specify the property of the entity that’s the proprietor of the connection.
@Entity
@Desk(identify = "manufacturers")
public class Model {

    @OneToOne(mappedBy = "manufacturers")
    personal BrandDetail brandDetail;
}
Enter fullscreen mode

Exit fullscreen mode


✅ Should you like this text, you can provide me a like on. 😎
Thanks for studying. 🙏

Spring Boot Information

Visit my page✅

Add a Comment

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

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?