-->
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.  [ 1 post ] 
Author Message
 Post subject: Joint query In hibernate not return not maching record
PostPosted: Wed Dec 05, 2012 2:46 am 
Newbie

Joined: Thu Nov 01, 2012 9:16 am
Posts: 1
have two tables abc and device

ABC :

Code:
CREATE TABLE `abc (   
       `Id` INT(11) NOT NULL AUTO_INCREMENT,   
       `empid` INT(11) DEFAULT NULL,   
       `empName` VARCHAR(500) DEFAULT NULL,   
      issueDate DATE DEFAULT NULL,   
       `deviceId` INT(11) DEFAULT NULL,   
       PRIMARY KEY (`allochardwareId`),   
       FOREIGN KEY (`deviceId`) REFERENCES `device` (`deviceId`)   
     ) ENGINE=INNODB  DEFAULT CHARSET=latin1;   


DEVICE

Code:
CREATE TABLE `device` (   
  `deviceId` INT(11) NOT NULL AUTO_INCREMENT,   
  `deviceName` VARCHAR(20) DEFAULT NULL,   
    quantity INT(11) DEFAULT NULL,     
       serialNo VARCHAR(20) DEFAULT NULL 
  `deviceTypeId` int(11) DEFAULT NULL,   
    PRIMARY KEY (`deviceId`),FOREIGN KEY (deviceTypeId`) REFERENCES `deviceType` (`deviceTypeId`);   
) ENGINE=INNODB DEFAULT CHARSET=latin1;


Mapping file for ABC

Code:
<many-to-one name="device" class="com.model.device" cascade="all" >
   <meta attribute="default-value">new Device()</meta>
   <column name="deviceId" />
</many-to-one>

My requirement is that

when a user searches for deviceName from the UI, it will fetch data first table and corresponding employee id assigned.
If it not assigned need to return null value from abc table but matching record from device table

It is the SQL query

Code:
SELECT * 
FROM abc
LEFT JOIN device
ON device.deviceId=abc.deviceId where device.serialNo="ee"

I wrote the corresponding HQL as

Code:
select abc from ABC ABC LEFT JOIN abc.device where device.serialNo="ee" 


here it returns only matching records in both tables. I need to retrieve records in such a way that even not matching also displayed with null values if record not found in another table.For example some records are available in device but not in ABC with serial no="ee" also need to displayed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.