-->
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: Criteria in Multiple Many-to-Many Entities
PostPosted: Tue May 27, 2014 12:55 pm 
Newbie

Joined: Tue May 27, 2014 12:44 pm
Posts: 1
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..


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.