-->
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: Left Outer joins in hibnerate
PostPosted: Sat Feb 16, 2013 7:47 am 
Newbie

Joined: Sat Feb 16, 2013 7:35 am
Posts: 2
I have two entities
a) Student
d) Address

I have not defined mappings between them (means in oject model I have not defined any mapping between these two but in database schema I have mapping between these two which is one to one) and for some students I may not have data in address table ....I dont want to define one to one relaion ship on object model...so my question is can I write HQL which has left Outer join ?


in SQL I fire query:- select * from student st left outer join address ad on st.studentId = ad.studentRfNum;
my DB design is :-

CREATE TABLE `student` (
`name` varchar(50) DEFAULT NULL,
`age` int(4) DEFAULT NULL,
`studentId` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`studentId`)
) ENGINE=InnoDB;

CREATE TABLE `address` (
`ADDRESSID` int(11) NOT NULL AUTO_INCREMENT,
`studentRfNum` int(11) NOT NULL,
`ADDLINE` varchar(45) NOT NULL,
`CITY` varchar(45) NOT NULL,
`STATE` varchar(45) NOT NULL,
`COUNTRY` varchar(45) NOT NULL,
PRIMARY KEY (`ADDRESSID`)
) ENGINE=InnoDB;

so is there any way to write HQL equivilant to above SQL? or is there anything which I am missing?


Top
 Profile  
 
 Post subject: Re: Left Outer joins in hibnerate
PostPosted: Sat Feb 16, 2013 7:54 am 
Newbie

Joined: Sat Feb 16, 2013 7:35 am
Posts: 2
Actually I want to load only student object not address.....but I want only those records for whom I have address in address table.....


Top
 Profile  
 
 Post subject: Re: Left Outer joins in hibnerate
PostPosted: Mon Feb 18, 2013 2:33 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
Hibernate does not define (left join on property = property) so you can 't build a join without mapping, but this has an exception (which i will cover below).
So this i just wanted you to know this for future.

But Hibernate does have a solution for your problem :
You can define your condition in where clause.
something like :
select a.*, p.* from Address a , Parent p
where a.studentNo = p.studentRefNo

So exception is you can have a inner join in this way without mapping.
And right, left and outer jons cant be acheived in this way.

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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.