openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Forrest Xia <>
Subject Re: @OrderBy not work?
Date Mon, 21 Sep 2009 03:44:45 GMT

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:
public class B {
  private f1;
  private f2;
  private f3;
  @JoinColumn(name = "f4_p1")
  @ManyToOne(fetch=FetchType.LAZY, optional=false)
  private A f4;

public class A {
  private p1;
  private p2;
  @OneToMany(mappedBy= "f4", 
  @OrderBy("f3 DESC")
  private Collection&lt;B&gt; p3;

public class C {
  private EntityManager em;
  public Collection&lt;B&gt; listB(String aKey) {
		A a = em.find(A.class, akey);
               // a.getP3() always return an empty list here, why?
               Collection&lt;B&gt; bs = a.getP3();
               Iterator itr = bs.iterator();
		while (itr.hasNext()) {
               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:
Sent from the OpenJPA Users mailing list archive at

View raw message