JPA criteriabuilder case query
•
Java
Can anyone provide an example of how to write a case query using criteriabuilder?
Solution
The following is a sample case expression using criteriabuilder (this applies to JPA 2):
Hashtable caseTable = new Hashtable(3); caseTable.put("Bob","Bobby"); caseTable.put("Susan","Susie"); caseTable.put("Eldrick","Tiger"); Expression expression = builder.get("firstName").caseStatement(caseTable,"NoNickname").equal("Bobby");
It generates the following SQL queries:
"CASE t1.firstName WHEN 'Bob' THEN 'Bobby' WHEN 'Susan' THEN 'Susie' WHEN 'Eldrick' THEN 'Tiger' ELSE 'NoNickname' END = 'Bobby'"
For more information, see JPA 2.0 case expressions
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码