Detailed explanation of Hibernate Commons Annotations in the Java Class Library
Hibernate Commons Annotations is a class library for the Hibernate of the Java persistence framework. It provides some commonly used annotations to simplify the operation of developers when using Hibernate.
1. @Entity Note: It is used to identify a class as a physical class, which will be maximized with the database.For example, we define a physical class called User:
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "username")
private String username;
// omit other attributes and methods
}
2. @Table Note: It is used to identify the mapping relationship between a physical class and the table in the database.For example, the above -mentioned physical category User and database table are mapping.
3. @ID Note: It is used to identify the primary key with a attribute as an entity class.
4. @GENERATEDVALUE Note: It is used to define the genetic strategy of the primary key.Common strategies are Identity, Sequence, Table, etc.For example, the ID field of the above -mentioned physical classes uses Identity strategy to generate primary keys.
5. @Column Note: It is used to identify the mapping relationship between a column in a database.For example, the username attribute of the above -mentioned physical classes and the username column of the database table User.
In addition to the above annotations, Hibernate Commons Annotations also provides some other annotations to achieve some common functions:
1. @Transient annotation: It is used to identify a column that does not with the database.For example, if there is a attribute token in the physical class, it does not require persistence to the database. You can use the @Transient annotation logo.
2. @onetomany and @Manytoone Note: It is used to identify the relationship between one -to -many and more pairs between the physical class.For example, if a user entity class has multiple Order entity classes, you can use the @Onetomany annotation logo. Conversely, if an order entity class belongs to a User entity class, you can use the @Manytoone annotation logo.
3. @joincolumn Note: The outer key column used to identify the relationship between the physical class.For example, if a user entity class has multiple Order entity classes, you can use @Joincolumn annotation to identify the associated relationship of user and order.
In short, Hibernate Commons Annotations is a class library provided by the Hibernate framework. It provides some commonly used annotations to simplify developers to use Hibernate for database operations.By using these annotations, developers can more conveniently define the mapping relationship between the physical class and the database table, as well as realizing the relationship between the physical class.