JPQL中有CASE表达式吗?
假设有一个表:
TableA:Field1, Field2, Field3
和关联的 JPA 实体类
@Entity
@Table(name="TableA")
public class TableA{
@Id
@Column(name="Field1")
private Long id;
@Column(name="Field2")
private Long field2;
@Column(name="Field3")
private Long field3;
//... more associated getter and setter...
}
有没有办法构造一个松散地转换为此SQL的JPQL语句,即如何将case表达式转换为JPQL?
select field1,
case
when field2 = 1 then 'One'
when field2 = 2 then 'Two'
else 'Other number'
end,
field3
from tableA;