What is the purpose of the @Column annotation in JPA?

4 phương ánCó giải thích

Các phương án trả lời

Chọn một phương án
Lời giảiChọn phương án để mở
Đáp án đúng: "It maps an entity field to a table column and allows setting column attributes". Trong JPA, mỗi trường persistent của entity mặc định ánh xạ tới cột cùng tên; @Column cho phép ghi rõ tên cột và các thuộc tính như name, nullable, unique, length, precision, scale, insertable, updatable, columnDefinition, ví dụ @Column(name = "full_name", nullable = false, length = 100). Hibernate dùng các thông tin này khi sinh DDL tạo bảng và khi dựng câu SQL. "It specifies the primary key field of an entity" là vai trò của @Id, thường đi cùng @GeneratedValue để sinh giá trị khoá. "It marks a field that should not be persisted" là @Transient, trường đó bị bỏ qua hoàn toàn khi lưu và nạp. "It defines a many-to-many relationship" là @ManyToMany, thường kèm @JoinTable để mô tả bảng nối giữa hai entity.

Cùng phần 1

Xuất hiện trong 1 bộ đề