Hi,
I'm trying to sort an arrayList using the annotation @orderBy.
I'm sure it's user error/inexperience with hibernate which is the problem. I have checked the logs coming out and i can't see any evidence of an order by happening.
I'm trying to order an arraylist of points by a point_id field. The points will not be unique.
Q. Is this possible?
Q. Am i using the correct syntax?
Q. Do i need to use the hibernate import not the javax.persistence one?
//should this be a hibernate library instead?
Code:
import javax.persistence.OrderBy;
@Entity
@Table(name = "polygons")
public class Polygon
{
@ManyToOne
@JoinColumn(name = "parent_session")
private Session parentSession;
@OneToMany(mappedBy = "parentPolygon", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE })
private List<Point> points = new ArrayList<Point>();
@OrderBy("point_id, asc")//also tried ("point_id asc")Code:
public List<Point> getPoints()
{
return points;
}}
...
//points table extract below
@Entity
@Table(name = "points")
public class Point
{
@Id
@GeneratedValue
@Column(name = "Id")
private long id;
@Column(name = "point_id")
private int point_id;Code:
@ManyToOne
@JoinColumn(name = "parent_polygon")
private Polygon parentPolygon;
}
http://www.onjava.com/pub/a/onjava/2007 ... tml?page=2 implied I could do this.
Many thanks,
s