-->
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: Joining Problems with Hibernate
PostPosted: Wed Sep 28, 2005 9:34 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
I have a problem with resultsets where some columns are null in the database.

For example I use the following Hibernate query:
Code:
Select c.conId, c.gId.gender, c.name, c.phoneId.prefix, c.phone, c.faxId.prefix, c.fax, c.email from EtContacts c where lower(c.etContactTypeMany.conTypeId) =:ConTypeId and lower(c.etEdiPartnerMany.paId) =:paId order by c.primary asc



This is the SQL, that is made by Hibernate
Code:
*/ select etcontacts0_.CON_ID as col_0_0_, etgenderty1_.GENDER as col_1_0_, etcontacts0_.NAME as col_2_0_, etphonepre2_.PREFIX as col_3_0_, etcontacts0_.PHONE as col_4_0_, etfaxprefi3_.PREFIX as col_5_0_, etcontacts0_.FAX as col_6_0_, etcontacts0_.EMAIL as col_7_0_ from EDITOOLS.ET_CONTACTS etcontacts0_, EDITOOLS.ET_GENDERTYPE etgenderty1_, EDITOOLS.ET_PHONE_PREFIX etphonepre2_, EDITOOLS.ET_FAX_PREFIX etfaxprefi3_, EDITOOLS.ET_CON2CONTYPE etcontactt4_, EDITOOLS.ET_CONTACT_TYPE etcontactt5_, EDITOOLS.ET_PA2CON etedipartn6_, EDITOOLS.ET_EDI_PARTNER etedipartn7_ where etcontacts0_.CON_ID=etedipartn6_.CON_ID and etedipartn6_.PA_ID=etedipartn7_.PA_ID and etcontacts0_.CON_ID=etcontactt4_.CON_ID and etcontactt4_.CON_TYPE_ID=etcontactt5_.CON_TYPE_ID and etcontacts0_.FAX_ID=etfaxprefi3_.FAX_ID and etcontacts0_.PHONE_ID=etphonepre2_.PHONE_ID and etcontacts0_.G_ID=etgenderty1_.G_ID and lower(etcontactt5_.CON_TYPE_ID)=? and lower(etedipartn7_.PA_ID)=? order by etcontacts0_.PRIMARY asc


The query shows some data, as long as all columns have data, but when for example the c.faxId.prefix is null in the Database, no data is shown. It seems to me, that there is a problem with the Joins Hibernate makes.

How can I change my Hibernate Query to work even if some columns are null?

thx
Regards



Hibernate version:
3.0.5


Top
 Profile  
 
 Post subject: Re: Joining Problems with Hibernate
PostPosted: Thu Sep 29, 2005 5:44 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
You need to use OUTER JOIN. Try with something like:

Code:
Select c.conId, g.gender, c.name, p.prefix, c.phone, f.prefix, c.fax, c.email
from EtContacts c left join c.faxId f left join c.gender g left join c.phoneId p
where lower(c.etContactTypeMany.conTypeId) =:ConTypeId and lower(c.etEdiPartnerMany.paId) =:paId order by c.primary asc


Hope syntax is correct, but this should be the way.
Regards
Alessandro


Top
 Profile  
 
 Post subject: Seems to me a bug!
PostPosted: Thu Sep 29, 2005 8:38 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
With Hibernate 3.0.5 I got the following stack:
Code:
java.lang.NullPointerException
   at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:264)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)


With the new 3.1 beta 3 it works -->Seems to me, that it's a BUG..? Is this bug already known, or should I report it?


Top
 Profile  
 
 Post subject: Re: Seems to me a bug!
PostPosted: Thu Sep 29, 2005 10:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Semmerl wrote:
With Hibernate 3.0.5 I got the following stack:
<snip>
With the new 3.1 beta 3 it works -->Seems to me, that it's a BUG..? Is this bug already known, or should I report it?


Why on earth would you report a bug that has already been fixed??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 10:16 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
Ok you are right ;-)
But is it really a Bug in 3.0.5?
Isn't there a possibilty to use an Outer Join like I need in 3.0.5 because I actually don't wanna use a Beta Version...


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.