Skip to content

Instantly share code, notes, and snippets.

@springcome
Last active September 1, 2016 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springcome/92824e8c1e5485260dffe13296b1e718 to your computer and use it in GitHub Desktop.
Save springcome/92824e8c1e5485260dffe13296b1e718 to your computer and use it in GitHub Desktop.
The use of 'CaseBuilder()' example
// String compare, Result Long
// query().from(cat).list(cat.name.when("Bob").then(1).otherwise(2));
// java.lang.ClassCastException: org.hibernate.hql.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.ast.tree.SelectExpression
// https://github.com/querydsl/querydsl/issues/185
query().from(cat).list(cat.name.when("Bob").then(Expressions.numberTemplate(Long, "1")).otherwise(Expressions.numberTemplate(Long, "2")));
// String hour compare, Result String
StringExpression amPm = new CaseBuilder().when(o.hour.lt("1200")).then("AM").otherwise("PM");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment