Which method is used to persist an entity in JPA EntityManager?
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: "persist()". Trong JPA, EntityManager.persist(entity) đưa một thực thể mới từ trạng thái transient (tạm thời) vào persistence context để nó thành managed; câu lệnh INSERT thực sự được gửi khi flush hoặc khi transaction commit. EntityManager còn có merge, remove, find, nhưng thêm mới là persist. "save()" là chỗ dễ nhầm: đó là phương thức của repository trong Spring Data JPA, và bên trong SimpleJpaRepository.save lại gọi persist hoặc merge tuỳ thực thể mới hay cũ, nó cũng có trong Session của Hibernate, nhưng không thuộc EntityManager. "insert()" không có trong API EntityManager, INSERT là câu SQL do JPA tự sinh. "store()" cũng không phải phương thức của EntityManager.
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 2 bộ đề
Đi tiếp từ đây