日期:2014-05-20 浏览次数:20799 次
@Entity @Table(name="student") @IdClass(StudentPK.class) public class Student { @Id public int getId() { return id; } @Id public String getName() { return name; } ... } StudentPK.java: public class StudentPK implements java.io.Serializable{ private int id; private String name; ... }
session1.beginTransaction(); StudentPK pk = new StudentPK(); pk.setId(1); pk.setName("Hiway"); Student s = (Student) session1.get(StudentPK.class, pk); System.out.println(s);