Hi,
I have the following problem with enumerated values and ordering, and can not seem to find an answer. I am trying to use the JPA annotations and queries only.
Hibernate entity manager 3.3.1.GA
I have these two classes:
@Entity
@Table(name="SEVERITY")
public class Severity implements Serializable, Comparable<Severity>{
public enum ImfLevel{
INFO, WARN, SEVERE, CRITICAL;
}
private String severitytext;
@Id
private String severity;
@Enumerated(EnumType.STRING)
@Column(name="SEVERITY", nullable = false, updatable = false)
private ImfLevel level;
@OneToMany(mappedBy="severity")
private Set<Event> events;
.....
}
and
@Entity
@Table(name="EVENT")
public class Event implements Serializable, EventIf {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private long eventid;
@Column(name = "EVENTTIME")
private Timestamp eventtime;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="SEVERITY")
private Severity severity;
. . . .
}
I am trying to query for events (and subset of events), and order them by severity, as defined in the enumerated type.
When I build the following query string I get a list ordered alphabetically.
"from Event event order by event.severity", ok so that seems reasonable.
Now I tried: "from Event event order by event.severity.level", but no luck, still ordered alphabetically. I also tried changing the EnumType to ORDINAL, but that did not change anything.
I have even tried:
"from Event event order by event.severity" and implemented Comparable on Severity, ordering it by level. . . . but still no luck.
Please point me to someplace that can point me in the right direction.
Thanks,
Shannon
_________________ Shannon Moyes Clark
|