I need some help with Hibernate Projections.
I have a class called Activity with a property "duration" which is an Enum. Duration is a Integer field on the Oracle Database. I have annotated the enum.
@TypeDefs({
@TypeDef(
name = "Duration",
typeClass = GenericEnumUserType.class,
parameters = {
@Parameter(name = "enumClass", value = "myproject.Duration"),
@Parameter(name = "identifierMethod", value = "getValue"),
@Parameter(name = "valueOfMethod", value = "getInstanceByValue") })
})
@Entity
@Table(name = "activity")
public class Activity {
...
private Duration duration;
...
}
The enum Duration has methods getValue() and getInstanceByValue(). The Value is an Integer.
I need to sum up the dutation of some Acitivities, that match my criterias. My DetachedCriteria looks something like this:
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Activity.class);
...
detachedCriteria.setProjection(Projections.sum("duration"));
When I execute this detachedCriteria I get the following ClassCastException:
myproject.Duration cannot be cast to java.lang.Integer
How can I sum over an enumeration field? It works on the database with pure SQL, therefore it should work with hibernate too somhow I assume.
Thanks for any help.