Hi J Grassel,
Thank you for the reply, yep, I got what you mean :)
After reviewing my code, I realized I might use a wrong program model, that
is, I ever operated on Entity B directly to get a list of B which belong to
the same Entity A, not through A's getCollectionRelationship().
However, I got another problem, I cannot get A's B list through A's
getCollectionRelationship() method, it always return an empty list. Seems
the OpenJPA does not automatically populate A's B list when I retrieve A
from database. Can you suggest how to make that? thanks a lot!
Here is the more complete sample code of how I am using it:
@Entity
public class B {
@Id
private f1;
@Column
private f2;
@Column
private f3;
@JoinColumn(name = "f4_p1")
@ManyToOne(fetch=FetchType.LAZY, optional=false)
private A f4;
}
@Entity
public class A {
@Id
private p1;
@Column
private p2;
@OneToMany(mappedBy= "f4",
fetch=FetchType.LAZY)
@OrderBy("f3 DESC")
private Collection<B> p3;
}
public class C {
private EntityManager em;
public Collection<B> listB(String aKey) {
A a = em.find(A.class, akey);
// a.getP3() always return an empty list here, why?
Collection<B> bs = a.getP3();
Iterator itr = bs.iterator();
while (itr.hasNext()) {
((B) itr.next()).getF1();
}
return bs;
}
}
J Grassel wrote:
>
> Whoops, commented out too many lines in the second example. Hope it is
> still clear on what I was trying to communicate.
>
--
View this message in context:
http://n2.nabble.com/OrderBy-not-work-tp3663648p3682971.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.