-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to select optional many-to-one
PostPosted: Thu Jun 22, 2006 8:07 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
I'm using Hibernate 3.2.0CR1 (distributed with JBoss 4.0.4 GA). I have an entity that looks like this (just mentioning the meaningful attributes):
Code:
@Entity
public class SomeEntity {
    @Id
    private Integer id;

    @ManyToOne(optional = true)
    @JoinColumn(name = "OTHER", nullable = true)
    private OtherEntity other;

    // other properties, getters and setters
}

@Entity
public class OtherEntity { ... }

Note that I can leave SomeEntity.other null. Now, when I query "select e from SomeEntity e" everything works fine. At a certain point I just want to get the "id" and "other" properties of a specific SomeEntity. The obvious way to do it would be to query "select e.id, e.other from SomeEntity e where e.id=:id". However, if "other" is null, the query returns no result at all.
Is there any way to get this query to return an array containing the id on the first position and null on the second?

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 7:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Does using an outer join help? "select e.id, e.other from SomeEntity e left outer join e.other where e.id=:id"

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 8:26 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Thank you, I though outer joins only worked for collections. Though I still believe it should be rated as a workaroundable bug.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.