My Table Structure is :
DROP TABLE IF EXISTS `htis_payroll`.`htis_users`; CREATE TABLE `htis_payroll`.`htis_users` ( `htis_employee_code` int(11) NOT NULL AUTO_INCREMENT, `htis_password` varchar(20) DEFAULT NULL, `htis_status` varchar(45) DEFAULT NULL, `htis_create_date` date DEFAULT NULL, `htis_employee_type` varchar(45) DEFAULT NULL, `htis_email` varchar(45) DEFAULT NULL, PRIMARY KEY (`htis_employee_code`) ) ENGINE=InnoDB AUTO_INCREMENT=3336 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `htis_payroll`.`htis_groups`; CREATE TABLE `htis_payroll`.`htis_groups` ( `htis_group_id` int(11) NOT NULL AUTO_INCREMENT, `htis_group_name` varchar(45) DEFAULT NULL, `group_status` tinyint(1) DEFAULT NULL, PRIMARY KEY (`htis_group_id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `htis_payroll`.`users_groups`; CREATE TABLE `htis_payroll`.`users_groups` ( `htis_employee_code` int(11) NOT NULL, `htis_group_id` int(11) NOT NULL, `htis_status` tinyint(1) DEFAULT NULL, `desc` varchar(45) DEFAULT NULL, PRIMARY KEY (`htis_employee_code`,`htis_group_id`), KEY `fk_users_groups_2_idx` (`htis_group_id`), CONSTRAINT `fk_users_groups_1` FOREIGN KEY (`htis_employee_code`) REFERENCES `htis_users` (`htis_employee_code`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_users_groups_2` FOREIGN KEY (`htis_group_id`) REFERENCES `htis_groups` (`htis_group_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `htis_payroll`.`htis_permissions`; CREATE TABLE `htis_payroll`.`htis_permissions` ( `htis_permission_id` int(11) NOT NULL AUTO_INCREMENT, `htis_permission_name` varchar(45) DEFAULT NULL, `htis_permission_desc` varchar(45) DEFAULT NULL, `htis_status` tinyint(1) DEFAULT NULL, `htis_permission_url` varchar(100) NOT NULL, `htis_icons` varchar(100) NOT NULL, PRIMARY KEY (`htis_permission_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `htis_payroll`.`groups_permissions`; CREATE TABLE `htis_payroll`.`groups_permissions` ( `htis_group_id` int(11) NOT NULL, `htis_permission_id` int(11) NOT NULL, `htis_status` tinyint(1) DEFAULT NULL, `htis_desc` varchar(45) DEFAULT NULL, PRIMARY KEY (`htis_group_id`,`htis_permission_id`), KEY `fk_groups_permissions_2_idx` (`htis_permission_id`), CONSTRAINT `fk_groups_permissions_1` FOREIGN KEY (`htis_group_id`) REFERENCES `htis_groups` (`htis_group_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_groups_permissions_2` FOREIGN KEY (`htis_permission_id`) REFERENCES `htis_permissions` (`htis_permission_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `htis_payroll`.`htis_special_permissions`; CREATE TABLE `htis_payroll`.`htis_special_permissions` ( `htis_employee_code` int(11) NOT NULL, `htis_permission_id` int(11) NOT NULL, `htis_special_permission` tinyint(1) DEFAULT NULL, PRIMARY KEY (`htis_employee_code`,`htis_permission_id`), KEY `fk_htis_special_permissions_2_idx` (`htis_permission_id`), CONSTRAINT `fk_htis_special_permissions_1` FOREIGN KEY (`htis_employee_code`) REFERENCES `htis_users` (`htis_employee_code`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_htis_special_permissions_2` FOREIGN KEY (`htis_permission_id`) REFERENCES `htis_permissions` (`htis_permission_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
My Fetch Query in database: select distinct (htis_permissions.htis_permission_id), htis_permissions.htis_permission_name, htis_permissions.htis_permission_url, htis_permissions.htis_icons from htis_permissions inner join groups_permissions ON htis_permissions.htis_permission_id = groups_permissions.htis_permission_id inner join users_groups ON groups_permissions.htis_group_id = users_groups.htis_group_id and htis_employee_code = '1000' and htis_permissions.htis_permission_id not in (select htis_special_permissions.htis_permission_id from htis_special_permissions where htis_special_permissions.htis_permission_id = htis_permissions.htis_permission_id and htis_special_permissions.htis_special_permission = 0) union select htis_permissions.htis_permission_id, htis_permissions.htis_permission_name, htis_permissions.htis_permission_url, htis_permissions.htis_icons from htis_permissions, htis_special_permissions where htis_permissions.htis_permission_id = htis_special_permissions.htis_permission_id and htis_special_permissions.htis_permission_id = '1000' and htis_special_permission = 1;
How to Best Perform in Hibernate to fetch Data.Please Help me..
|