|
Enum:
public enum TargetKind {
PERSON,
PLACE,
EVENT,
}
DTO class:
public class SlugLink implements Serializable {
private String canonicalPath;
private String path;
@Enumerated(EnumType.STRING)
private TargetKind targetKind;
private String targetId;
public SlugLink() {
}
public SlugLink(String canonicalSlug, String path, TargetKind targetKind, Serializable targetId) {
this.canonicalPath = canonicalSlug;
this.path = path;
this.targetKind = targetKind;
this.targetId = targetId.toString();
}
Expects the following query to work:
but Hibernate throws error:
As mentioned here (http://stackoverflow.com/questions/8503845/jpql-enum-literal-in-select-new-query#comment10545103_8508345), enum literal should be supported in SELECT NEW.
Workaround: change the enum constructor parameter to String
|