hibernate session.get(class,serialid) 方法为空值的原因?
package hibernate.test; import hibernate.test.pojo.Person; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Configuration config=new Configuration().configure(); ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); SessionFactory sFactory=config.buildSessionFactory(sr); Session session=sFactory.openSession(); Transaction tx=session.beginTransaction(); Person person=(Person)session.get(Person.class, 12);//老是说空值,也就是没有获得对象,为什么呢??? person.setName("oscasfsfsfr"); person.setPassword("sfasf1ddd"); //Person person=new Person();//临时对象 session.merge(person); tx.commit(); session.close(); } }
Exception in thread "main" java.lang.NullPointerException
at hibernate.test.Test.main(Test.java:23)
person.java
package hibernate.test.pojo; public class Person { private Integer id; private String name; private String password; 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; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。