Hi,
We're running hibernate 3.2.0, and I'm trying to figure out how I can get objects in an appropriate order when using a one-to-many mapping.
I basically have two classes, Parent and Child, where Parent contains a list of Child objects.
Code:
class Parent {
  @Id
  String id;
  @OneToMany(cascade= CascadeType.ALL,
        fetch= FetchType.EAGER,
        targetEntity = Child.class )
    @JoinTable(name = "parent__child",
               joinColumns = @JoinColumn(name = "parent__id"),
               inverseJoinColumns = @JoinColumn(name = "child__id"))
    @IndexColumn(name = "idx")
  List<Child> children;
}
class Child {
  @id
  String id;
  @Column(nullable = false)
  String str;
}
There are a bunch of other fields in the real code, including multiple collections in Parent, but that's enough for this question.
Conceptually what I need to query is
Code:
select p.id, c.str
  from Parent p,
  join p.children as c
  where ... some complex logic on parent;
but I need the child data to show up in the order they actually exist in the parent's array.  I did some web searching and tried adding "order by p.id, index(c)" but I'm getting an error message from hibernate:
Quote:
index() function not supported for many-to-many association
Odd, considering it's actually a one-to-many, but I suspect that's just a copy/paste issue in the code.
Anyway, can I do what I want to do without going all the way to SQL? I can't just rely on hibernate to instantiate the parent objects and load the children because I'm streaming through thousands of objects and hibernate falls into the N+1 queries tar pit (there are multiple collections to join).
Any suggestions would be greatly appreciated.