Hibernate get record by matching value with 2 concat fields
I have a value which must be matched with 2 fields concatenation( value = field1+field2) and return result object matching that criteria. Can I somehow do it via Criteria or I need to 开发者_运维技巧use Query to resolve this ?
Thank you for answering.
Hibernate doesn't have this functionality implemented. There are some ways of doing this.
One is using a SQLRestriction, which is database dependent. Another one is creating a field with a concatenate formula, also DB dependent.
I fixed the problem by creating a new Criterion for Hibernate. You can read more about it, here. http://whaticode.com/2013/02/01/hibernate-criteria-concatenate-fields-in-like-and-ilike-operators/
I hope it helps.
This is not very elegant, but it works:
result.add(Restrictions.ilike("dni || this.letter", "%" + dniWithLetter + "%"));
精彩评论