Hibernate条件在SQLite中不起作用
我的装备:Hibernate条件在SQLite中不起作用,hibernate,sqlite,Hibernate,Sqlite,我的装备: 休眠3.6.9 Hibernate SQLite方言来自 我的实体类很简单 @Entity @Table(name = "RegistrationRequests") public class RegistrationRequest { @Id @GeneratedValue Integer id; String uuid; ... getters and setters ... } uuid被分配给uuid.randomUUID().
- 休眠3.6.9
- Hibernate SQLite方言来自
@Entity
@Table(name = "RegistrationRequests")
public class RegistrationRequest {
@Id
@GeneratedValue
Integer id;
String uuid;
... getters and setters ...
}
uuid被分配给uuid.randomUUID().toString(),并正确地保存在数据库中。
现在,问题是当我尝试使用Hibernate标准从数据库检索存储的请求时
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'
结果正确(即从数据库中选择了一条记录)
我有点困惑,尝试了所有的方法都没有结果…据我所知,就hibernate api而言,您不必自己设置where子句的值(我使用Nhibernate),因此当您将where子句的值设置为“myValue”时,您实际上是在搜索字符串,以匹配“myValue”,在您想要的位置搜索myValue 更改此选项有望使其正常工作:
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(RegistrationRequest.class);
criteria.add(Restrictions.eq("uuid", uuid));
List requests = criteria.list();
'\''+uuid+'\''
看起来很奇怪。如果使用uuid时没有“around the uuid”,会发生什么情况?这没有多大帮助,因为SQLite无法使用连字符处理查询,所以我需要引用参数。没有引号SQLite抱怨:错误:无法识别的标记:“4c7e”当您有上述条件查询时,生成的查询是什么?该查询与我的帖子中完全相同,只是uuid周围没有引号。当我尝试执行此语句时,SQLIte抱怨无法识别令牌。我认为这可能是SQLite特有的问题。。。