I'm having trouble figuring out how to come up with a query (Criteria or HQL) for this, but it seems like it shouldn't be too hard.
Here's what I have:
Category is an Enum.
class Content:
Collection categories
In my config, I'm mapping categories like this:
Code:
<bag name="categories" table="contents_categories" cascade="all" lazy="true">
<key column="contentId" />
<element column="category" type="com.foo.hibernate.usertypes.CategoryUserType"/>
</bag>
CategoryUserType extends the EnumUserType listed here:
http://www.hibernate.org/265.htmlThe relevant tables and fields look like this:
Code:
DROP TABLE IF EXISTS `foo`.`content`;
CREATE TABLE `foo`.`content` (
`id` bigint(20) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `foo`.`contents_categories`;
CREATE TABLE `foo`.`contents_categories` (
`contentId` bigint(20) unsigned NOT NULL auto_increment,
`category` varchar(45) NOT NULL default '',
PRIMARY KEY (`contentId`,`category`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What I'd like to be able to query is getting back all of the Content objects that have a given Category in it's list of categories. Doesn't seem like it should be too hard, but I'm not sure how to get back Content based on the categories that it has.
Any help is greatly appreciated. We're using Criteria for our other queries, but either Criteria or HQL is fine.
Thanks in advance.