문제

I have a composite primary key for my object.How can i use a jpa to update my object?

Normally we use the following code

EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa");
EntityManager em = emf.createEntityManager();
Student stud1 = em.find(Student.class,1);
stud1.setSname("Deepak");
//set others
em.merge(stud1);
em.getTransaction().commit();

Now if i have a object whose primary key is composite then how can i implement update?

도움이 되었습니까?

해결책

Pretty much the same, except that you'll have to construct the primary key object:

Student stud1 = em.find(Student.class, new StudentPK(pkPart1, pkPart2));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top