-->
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: Outer Join
PostPosted: Tue Aug 09, 2005 9:26 am 
Newbie

Joined: Thu May 20, 2004 5:40 pm
Posts: 10
Location: Rio de Janeiro - Brazil
Hibernate version: 3.0

Name and version of the database you are using: Oracle 8i

Hi everybody,
i'm trying to do the following query using the Criteria API.

Code:
SELECT ename, job, dept.deptno, dname
    FROM emp, dept
    WHERE emp.deptno(+) = dept.deptno
        AND job(+) = 'CLERK';


I wanna know if the Criteria API generates a query like the above, putting in
the WHERE clause the (+) operator in an outer join.
Could anyone give some examples if so, please?

Best regards.
Alexandre Martins.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 9:41 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Well, up to Oracle 9i no ANSI joins are supported. Thus, the proprietary Oracle syntax using the (+)-operator is neccessary. This is of course supported by Hibernate (see org.hibernate.sql.OracleJoinFragment).

I don't know, if outer joins are supported with Criteria API. I remember some thread stating that it hasn't been implemented so far. But I can be wrong.

Anyway, you can use HQL or native SQL to get a solution.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 9:51 am 
Newbie

Joined: Thu May 20, 2004 5:40 pm
Posts: 10
Location: Rio de Janeiro - Brazil
Ok Sven,
that's what i'm doing, but as soon as i can do it with Criteria, i'll migrate.
Thank you very mutch!
Best regards,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 10:40 am 
Newbie

Joined: Thu May 20, 2004 5:40 pm
Posts: 10
Location: Rio de Janeiro - Brazil
Do you know how can i do it using HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 10:47 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Without having tested it and assuming your classes are called "Emp" and "Dept".

Code:
StringBuffer queryString = new StringBuffer(120).
   append("SELECT e.ename, e.job, d.deptno, d.dname ").
   append("FROM Emp e ").
   append("LEFT OUTER JOIN Dept d ").
   append("WHERE e.job IS NULL OR e.job = :jobValue");
Query query = session.createQuery(queryString.toString());
query.setString("jobValue", "CLERK");
List result = query.list();


Best regards
Sven


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.