错误: Session类型中的get(Class,Serializable)方法不适用于参数(Class,int)?
public class Test {
public static void main(String[] args) {
Configuration config = new Configuration().configure();
SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();
Transaction trx = session.beginTransaction();
Sample sample = new Sample();
sample = (Sample)session.get(Sample.class, 1);
trx.commit();
System.out.println("success");
session.close();
}
}
public class Sample {
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
答案 0 :(得分:0)
你应该使用
...
sample = (Sample)session.get(Sample.class, new Integer(1));
...
而不是简单的int。