-->
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.  [ 5 posts ] 
Author Message
 Post subject: order by und left join
PostPosted: Wed Dec 09, 2009 6:20 am 
Newbie

Joined: Wed Jul 19, 2006 4:13 am
Posts: 6
Angenommen ich habe folgende Klassen (alles vereinfacht dargestellt):

Code:
@Entity
public class ObjectA {
    @Id
    private int id;
    @ManyToOne
    private Objectb b;


Code:
@Entity
public class ObjectB {
    @Id
    private int id;
    private einstring;
}


Nun möchte ich nach "einstring" sortieren.

Code:
from ObjectA order by b.einstring


Hibernate macht daraus dann einen SQL-Query ähnlich dem folgenden:

Code:
select * from objecta,objectb where ojbecta.b=objectb.id order by objectb.einstring;



Lässt sich das auch so ändern, dass statt des inner joins ein left join verwendet wird?


Top
 Profile  
 
 Post subject: Re: order by und left join
PostPosted: Thu Dec 10, 2009 5:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Probiere mal die Query
Code:
from ObjectA a join a.b b order by b.einstring

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: order by und left join
PostPosted: Thu Dec 10, 2009 6:01 am 
Newbie

Joined: Wed Jul 19, 2006 4:13 am
Posts: 6
mmerder wrote:
Probiere mal die Query
Code:
from ObjectA a join a.b b order by b.einstring



Wenn ich daraus
Code:
from ObjectA a left join a.b b order by b.einstring
mache (als ein left join), dann enthält meine ResultList zwar auch die NULL-Werte, jedoch besteht jeder Eintrag der Liste aus einem Array mit ObjectA und ObjectB. Ich benötige allerdings nur ObjectA, da b ja bereits enthalten ist.


Top
 Profile  
 
 Post subject: Re: order by und left join
PostPosted: Thu Dec 10, 2009 6:25 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Code:
select a from ObjectA a join a.b b order by b.einstring

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: order by und left join
PostPosted: Thu Dec 10, 2009 6:28 am 
Newbie

Joined: Wed Jul 19, 2006 4:13 am
Posts: 6
mmerder wrote:
Code:
select a from ObjectA a join a.b b order by b.einstring


Das hilft. Besten Dank!


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

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.