-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Help with queries not using enumerated order
PostPosted: Mon Jan 28, 2008 3:04 pm 
Newbie

Joined: Mon Jan 28, 2008 1:50 pm
Posts: 9
Location: EMC
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 3:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I cannot directly give you an answer to your problem, but have you tries to set the show_sql property in order to trace the actual SQL queries. Maybe this will give you some hints on what is going on.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ordinal should do the trick. the order by is implemented at the DB level, not in memory.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.