我遇到了错误。似乎数据库查询返回一个空值,即使我正在使用的值和查询是正确的。
public Ods_Gis_Actel getById(String id) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Ods_Gis_Actel a = (Ods_Gis_Actel) session.get(Ods_Gis_Actel.class,new String(id));
return a;
}
(Log4j在控制台中显示正确的查询,我确信我正在搜索的行存在于表中。)
查询getAll()工作正常,所以我认为这意味着映射是正确的。 它可以是hibernate.util吗?
public class HibernateUtil { public static final SessionFactory sessionFactory;
static {
try {
// Creation of SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure("Hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
// public static final ThreadLocal session = new ThreadLocal();
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
感谢,