-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: index column in one-to-many mapping
PostPosted: Thu Jul 12, 2007 9:28 pm 
Newbie

Joined: Thu Jul 12, 2007 9:01 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.