In a JPA One-to-Many relationship, what does the mappedBy attribute of the @OneToMany annotation specify?
4 phương ánCó giải thích
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: "The field in the "many" side entity that maps back to the "one" side entity.". Trong quan hệ hai chiều, ví dụ Department có danh sách employees đánh dấu @OneToMany và Employee có trường department đánh dấu @ManyToOne, mappedBy trên phía Department ghi tên trường department ở phía nhiều; nó báo JPA rằng phía nhiều mới là phía sở hữu quan hệ (owning side), nơi giữ cột khoá ngoại, còn phía một chỉ phản chiếu nên không sinh thêm cột hay bảng nối. "The database table name." sai vì tên bảng đặt bằng @Table. "The primary key of the "many" side entity." sai vì khoá chính của entity bên nhiều khai báo bằng @Id trong chính entity đó, mappedBy không nhắc tới khoá. "The join table name." sai vì bảng nối đặt bằng @JoinTable, và dùng mappedBy chính là để khỏi cần bảng nối mà tái dùng khoá ngoại phía nhiề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