What is the purpose of the following annotation in JPA? @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
4 phương ánCó giải thích
private Long id;Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "It marks the field as the primary key with auto-increment strategy". Lần theo mã: @Id đánh dấu trường id là khoá chính của entity, còn @GeneratedValue(strategy = GenerationType.IDENTITY) báo JPA không tự cấp giá trị mà để cột identity hay auto-increment của cơ sở dữ liệu sinh khi INSERT, sau đó provider đọc lại khoá vừa sinh và gán vào trường id kiểu Long. "It creates a foreign key for the entity" sai vì khoá ngoại khai báo bằng @ManyToOne hoặc @OneToOne kèm @JoinColumn, không phải @Id. "It marks the field as a version column" sai vì cột phiên bản cho khoá lạc quan (optimistic locking) dùng @Version. "It disables the persistence of the field" sai vì muốn một trường không được lưu xuống bảng thì dùng @Transient; ở đây trường id lại là trường quan trọng nhất được lưu.
Cùng phần 1
If you have a Student entity and a Course entity with a Many-to-Many relationship, and you want to fetch all students enrolled in a specific course, how would you typically structure the query in JPA?Có lời giảiCâu hỏiWhich annotation is used to define a JPA Many-to-Many relationship?Có lời giảiCâu hỏiWhat is the purpose of the @Column annotation in JPA?Có lời giảiCâu hỏiCả 40 câu của chủ đề40 câu
Xuất hiện trong 1 bộ đề
Đi tiếp từ đây