-->
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.  [ 2 posts ] 
Author Message
 Post subject: Join Question
PostPosted: Thu May 13, 2010 6:38 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Hi

Hoping this is a basic question. Hibernate is executing this query (which I've converted to SQL to make it easier to read)

select a.*
from account a, person p
where (a.personID=p.personID)
and (a.username like 'ABC123')
and p.person_state<>'left'
and p.person_state<>'missing'
and p.person_state<>'absent'
and p.person_state<>'deleted'
order by p.RealName asc, p.forenames asc limit 10;

In my Account object, the relationship with Person is as follows

Code:
    @OneToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="personID", nullable=true)
    @NotFound(action=NotFoundAction.IGNORE)
    private Person person;


Unfortunately, its a legacy database, and instead of having a null value for the personID when there isn't a matching Person record, it has -1. My join (and therefore my query) fails (there are no Person records with an id of -1)

Is there a way to modify the join to bring back results even when Account.personID = -1?

Thanks


Top
 Profile  
 
 Post subject: Re: Join Question
PostPosted: Thu May 13, 2010 9:51 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Fixed it. Was concentrating on the mapping, and forgot that a JPA query will override any entity mappings.

This is my query now:

select a from Account a left join a.person p where ...


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