0

Example:

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
            ))
    }
}

As in the example above, I would like to get string value of enum ShapeType in DTO object. How should this conversion look like? I tried as in the example above and looks good, but when I use shapeType.stringValue() and then Hibernate create query with call function to_char(Oracle) or str (Sybase), as in example:

SELECT TO_CHAR(ShapeType) From Shape;

Why? How to fix it?

Pablo
  • 173
  • 1
  • 3
  • 14
  • Edit please, seems ununderstandable – sForSujit Jul 27 '17 at 11:49
  • 1
    I can't believe, that it may even compile... `@Enumerated("EnumType.STRING")` this part should looks like `@Enumerated(EnumType.STRING)`, both from package `javax.persistence` – Krzysiek Jul 27 '17 at 12:06
  • @Krzysiek, Yes you're right, but it's not important... this is an illustrative example... – Pablo Jul 27 '17 at 12:16

0 Answers0