Hibernate Annotation:
@Entity: Used to mark a class as an entity that is mapped to a database table.
@Table: Specifies the name of the database table associated with an entity. It can also define additional table properties like the schema, indexes, etc.
@Column: Maps a field or property to a column in the database table. It allows you to specify various attributes such as name, length, nullable, unique, etc.
@Id: Specifies the primary key of an entity.
@GeneratedValue: Used in conjunction with @Id to specify the strategy for generating primary key values. It can take values like AUTO, IDENTITY, SEQUENCE, TABLE, etc.
@ManyToOne: Defines a many-to-one association between entities. It is used to map a foreign key relationship where multiple entities of one type are associated with a single entity of another type.
@OneToMany: Establishes a one-to-many association between entities. It is used to define a collection of entities that are associated with a single entity of another type.
@OneToOne: Specifies a one-to-one association between entities. It is used to define a unique relationship where each entity of one type is associated with exactly one entity of another type.
@JoinTable: Specifies the join table for a many-to-many relationship.
@JoinColumn: Specifies the join column used for a relationship. It allows you to specify the name of the column, its nullable property, and other attributes.
@Transient: Marks a field or property as transient, indicating that it should not be persisted to the database.
@Embedded: Indicates that a field or property contains an embedded object. It is used to map complex or composite types that are stored within the same table.
@Embeddable: Marks a class as embeddable, allowing it to be used within another entity or component.
@ElementCollection: Maps a collection of basic types or embeddable objects.
@Cascade: Defines cascading behavior for entity associations, such as SAVE_UPDATE, DELETE, MERGE, etc.
@Fetch: Specifies the fetching strategy for associations, such as EAGER or LAZY.
@Cacheable: Enables or disables the second-level caching for an entity or collection.
@NamedQuery: Defines a named query.
@NamedQueries: Defines a list of named queries.
@NamedNativeQuery: Declares a named native SQL query for an entity.
@Version: Indicates a version property for optimistic locking.
These are just a few of the commonly used Hibernate annotations. Hibernate provides many more annotations for various purposes, including caching, fetching strategies, auditing, and more.
0 Comments