简体   繁体   English

为“字符串之间”创建休眠限制

[英]Creating Hibernate Restriction for 'between' Strings

I'd like to compare if a String is greater than or equal and less than or equal another two Strings. 我想比较一个字符串是否大于或等于并且小于或等于另外两个字符串。

Example: 例:

"C" between "A" and "F" > true “ A”和“ F”之间的“ C”> true

I tried: 我试过了:

Criteria criteria = session.createCriteria();
criteria.add(Restrictions.ge("START_VALUE_COLUMN", "C")) 
        .add(Restrictions.le("END_VALUE_COLUMN", "C"));

But that's not working for me. 但这对我不起作用。

How can I add this Restriction in Hibernate? 如何在休眠中添加此Restriction

I think you have you have swapped the operators. 我认为您已经交换了运营商。

Your criteria results in: 您的条件导致:

... where START_VALUE_COLUMN >= "C" and END_VALUE_COLUMN <= "C"

Turn them around: 转过来:

Criteria criteria = session.createCriteria();
criteria.add(Restrictions.le("START_VALUE_COLUMN", "C")) 
        .add(Restrictions.ge("END_VALUE_COLUMN", "C"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM