-2
在使用Hibernate,JSF進行項目時,我想出了一個問題。從看起來,我的程序在通過此處使用的addTemp方法存儲數據時遇到問題Roofhelper.java文件休眠數據庫session.save不會在數據庫中添加記錄
public class RoofHelper {
SessionFactory factory = NewHibernateUtil.getSessionFactory();
public static void main(String[] args) {
RoofHelper RoofM = new RoofHelper();
}
public String emailAvailable(String email) {
String result;
Transaction tx = null;
Session session = null;
session = factory.openSession();
try {
tx = session.beginTransaction();
Query query = session.createQuery("from User user where user.email= :email").setParameter("email", email);
User user = (User) query.uniqueResult();
tx.commit();
if (user == null) {
result = "a";
} else {
result = "na";
}
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
e.printStackTrace();
result = "dbp";
} finally {
session.close();
}
return result;
}
/* Add to database a temp user */
public String addTemp(String email, String password, String fname, String lname, int phoneNumber, Boolean buyer, Boolean seller, Boolean renter, Boolean tenant) {
String result;
Session session = null;
session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Temp temp = new Temp(fname, lname, email, password, phoneNumber, buyer, seller, renter, tenant);
session.persist(temp);
tx.commit();
result = "s"; // success
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
result = "f";//failure
}
result = "ff";
e.printStackTrace();
} finally {
session.close();
}
return result;
}
}
而emailAvailable方法執行得很好,在addTemp只是套牢中返回的 「FF」 字符串。
好吧。在這種情況下,Hibernate正在拋出一個異常。什麼是堆棧跟蹤? – Desorder 2014-09-23 21:23:07
嘿@Desorder,檢查這個TXT,我認爲它有來自Apache的Tomcat輸出信息https://dl.dropboxusercontent.com/u/48247518/stuff.txt – sobek 2014-09-23 22:07:40
我相信這一切都歸結爲這個問題:組織。 hibernate.PropertyValueException:非空屬性引用一個空值或瞬態值:roof.Temp.email – sobek 2014-09-23 22:26:27