Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Problem with QueryHints.FETCH and ORDER BY clause
Problem with QueryHints.FETCH and ORDER BY clause [message #1064199] Tue, 18 June 2013 04:41 Go to next message
Eclipse UserFriend
Hi!
just a question.

If I have

@OneToMany(mappedBy="recapito", cascade = {CascadeType.PERSIST,CascadeType.MERGE})
private List<Recapito> r;

and i set
query.setHint(QueryHints.FETCH, "dip.r");

and i execute a query with ORDER BY clause on Recapito attributes, why this sort is not maintained?

Re: Problem with QueryHints.FETCH and ORDER BY clause [message #1064298 is a reply to message #1064199] Tue, 18 June 2013 10:58 Go to previous messageGo to next message
Eclipse UserFriend
If you want a relationship to be ordered, you should put the order by on the mapping, not in the query.

With the order by in the query, I would expect the results to be ordered, unless they were already cached.
Re: Problem with QueryHints.FETCH and ORDER BY clause [message #1064510 is a reply to message #1064298] Wed, 19 June 2013 11:02 Go to previous messageGo to next message
Eclipse UserFriend
So, i added @OrderBy annotation:

@Entity
@Table(name="DIPENDENTE")
public class Dipendente implements Serializable {

............

@ManyToOne
@JoinColumn(name="cRecapito")
private Recapito r;
}

@Entity
@Table(name="RECAPITO")
public class Recapito implements Serializable {

............

//uni-directional many-to-one association to GpfSegment
@ManyToOne
@JoinColumn(name="cComune")
@OrderBy(value="cIstat")
private Comune c;
}

@Entity
@Table(name="COMUNE")
public class Recapito implements Serializable {

............

@Id
@Column(name="cIstat")
private String cIstat;
}

List<Dipendente> is my result but is not order by cIstat...where is the error?
Re: Problem with QueryHints.FETCH and ORDER BY clause [message #1064541 is a reply to message #1064510] Wed, 19 June 2013 15:07 Go to previous message
Eclipse UserFriend
You show a JoinColumn on a ManyToOne that has nothing to order as it references a single Comune entity. Did you put the orderBy on a ManyToOne or ManyToMany, and how are you reading in the owning entity? Also remember that the orderby only applies if the object is loaded from the database, and it is up to the application to maintain this order. If the application creates the owning entity and doesn't have the collection in order, or changes the order, this is what is presented to the application until it is reloaded from the database.
Previous Topic:InheritancePolicy SingleTableStrategy in Dynamic Persistence
Next Topic:merge problem
Goto Forum:
  


Current Time: Wed Jul 23 15:33:29 EDT 2025

Powered by FUDForum. Page generated in 0.06330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top