工作我的裝備:從http://code.google.com/p/hibernate-sqlite/休眠條件不SQLite的
我的實體類是簡單
的Hibernate 3.6.9
休眠SQLite的話,
@Entity @Table(name = "RegistrationRequests") public class RegistrationRequest { @Id @GeneratedValue Integer id; String uuid; ... getters and setters ... }
將uuid分配給UUID.randomUUID()。toString(),並正確保留在數據庫中。 現在,問題是當我嘗試使用Hibernate Criteria從數據庫檢索存儲的請求時。
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RegistrationRequest.class); criteria.add(Restrictions.eq("uuid", '\'' + uuid + '\'')); List requests = criteria.list();
總是產生一個空的結果,但是,如果我執行生成的SQL,
select this_.id as id2_0_, this_.created as created2_0_, this_.email as email2_0_, this_.isVerified as isVerified2_0_, this_.name as name2_0_, this_.password as password2_0_, this_.surname as surname2_0_, this_.uuid as uuid2_0_ from RegistrationRequests this_ where this_.uuid='ced61d13-f5a7-4c7e-a047-dd6f066d8e67'
結果是正確的(即一個記錄從數據庫中選擇)。
我有點爲難,試圖沒有結果一切......
的' '\' '+ UUID + '\'''看起來很奇怪。如果你使用uuid而沒有'arround uuid?會發生什麼? – andih 2012-04-15 19:44:58