示例:
public enum ShapeType {
CIRCLE, SQUARE, RECTANGLE TRIANGLE
}
public ShapeEnity {
@Enumerated(EnumType.STRING)
private ShapeType shapeType;
.......
}
public ShapeDTO {
private String shapeType;
....
}
public ShapeFinder {
public ShapeDTO find() {
QShape shape = QShape.shape;
return createQuery()
.from(shape)
.list(Projections.fields(ShapeDTO.class,
shape.shapeType.stringValue
))
}
}
如上例所示,我想在DTO对象中获取枚举ShapeType的字符串值。这种转换应该如何? 我在上面的示例中尝试过并且看起来不错,但是当我使用shapeType.stringValue()然后Hibernate使用调用函数to_char(Oracle)或str(Sybase)创建查询时,如示例所示:
SELECT TO_CHAR(ShapeType) From Shape;
为什么呢?如何解决?