-->
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: Optional Association and Outer Join
PostPosted: Wed Feb 18, 2009 1:11 pm 
Newbie

Joined: Wed Feb 18, 2009 12:57 pm
Posts: 3
Hey guys,

I have an optional FK association that I mapped as follows:

@OneToOne(optional=true,fetch=FetchType.LAZY,cascade=CascadeType.ALL)
@JoinColumn(name = "OP_STS_ID", referencedColumnName="CTGY_ID",nullable=true,insertable = false, updatable = false)
@NotFound(action=NotFoundAction.IGNORE)
private Category operatingStatus;


The idea is that not every value in the column OP_STS_ID will have a valid FK to the category table; that's what makes the relationship optional.

However, this is not working at all. When querying using HQL Hibernate is using an inner join and I need it to do an outer join to grab all the values.... So right now it issues "and event0_.OP_STS_ID=category5_.CTGY_ID " and I NEED it to issue "and event0_.OP_STS_ID=category5_.CTGY_ID (+)"

The (+) should indicate that this association is optional, but I can't get it to work!!

This is the HQL:

Query q = s
.createQuery("select distinct e from Event e join e.facilities "
+ "assc join e.scheduleList sch join sch.dailyViewList dv "
+ "where assc.facility.id=80007838 and (e.operatingStatus.englishName is null" +
" or e.operatingStatus.englishName <> 'Closed')"
+ "and dv.scheduleDate>? and dv.scheduleDate<?");

Please help!


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.3.1GA

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 3:24 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You are currently using an implicit join to the 'operatingStatus' (e.operatingStatus.englishName ....). Hibernate never generates outer joins in this case. You need to do an explicit 'left join'. Eg.

Code:
... left join e.operatingStatus opstat .... where ... opstat.englishName is null ...


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.