I have:
@Column(name = "UserType", nullable = false)
@Enumerated(EnumType.STRING)
private UserType userType;
How to return this field by SQL request using addScalar() method?
This is how you add an Enum to a SQLQuery
You define a properties object
Properties params = new Properties();
params.put("enumClass", "UserType");
params.put("type", "12"); /*EnumType.STRING type = 12 */
You resolve your enum type:
Type userEnumType = sessionFactory.getTypeHelper().custom(UserType.class, params);
You execute your query:
List<SomeEntity> result = getSession().createSQLQuery("select e from SomeEntity ")
.addScalar("userType", userEnumType)
.setResultTransformer(Transformers.aliasToBean(SomeEntity.class))
.list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With