0
我在JPA 2.0和Hibernate 4.2.19.Final中使用Spring,我尝试构建一个动态查询,它具有从Restrictions
类生成的简单谓词方法。 Restrictions.like("attributes.value" + value.getKey() , value.getValue());
。我的实体存储在一个稀疏表中,其中列的编号与属性描述相关。当使用限制时,Hibernate的criteria.list()返回空列表。
实体:
@Entity
@Table(name = "MY_ENTITIES")
public class Entity {
@Id
@GeneratedValue
Long id;
@Embedded
Attributes attributes;
}
@Embeddable
public class Attributes{
/** Attribute 1. */
@Embedded
@Column(name = "value_1")
private String attribute1;
*
/** Attribute N. */
@Embedded
@Column(name = "value_N")
private String attributeN;
}
有复杂谓词诸如AND,OR,NOT谓词其通过嵌套上述简单谓词获得。
一切似乎运作良好时,我使用AND和OR谓词,但更复杂的表达式,其中涉及NOT,例如:
((attribute1=% OR attribute2=%) AND attribute3=%) AND NOT attribute4=%
的Criteria.list()方法返回空列表时DB中有实体满足标准。
有什么建议吗?