I want to fetch all ancestors or parent tree from self reference table
my table structure CREATE TABLE `category` ( `CATEGORY_ID` int(11) NOT NULL auto_increment, `CATEGORY_NAME` varchar(150) NOT NULL, `PARENT_CATEGORY_ID` int(11) default NULL, PRIMARY KEY (`CATEGORY_ID`), KEY `CATEGORY_NAME` (`CATEGORY_NAME`), KEY `FK31A8ACFEAF2C96DF` (`PARENT_CATEGORY_ID`), CONSTRAINT `FK31A8ACFEAF2C96DF` FOREIGN KEY (`PARENT_CATEGORY_ID`) REFERENCES `category` (`CATEGORY_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
sample data 1,cat-1,null 2,cat-2,1 3,cat-3,2 4,cat-4,3 5,cat-5,4 6,cat-6,5 7,cat-7,6 8,cat-8,null 9,cat-9,8 10,cat-10,9 11,cat-11,10 12,cat-12,11 13,cat-13,12 14,cat-14,13
This could be n level tree
Please tell me how could I fetch all parents ids efficiently using hibernate criteria of any specific category for example I give input 12 and it will return 11,10,9,8 in list Haroon Idrees
|