I have three tables:
Code:
item (id serial, ...)
item_title (id serial, item_id integer, title_id integer, active boolean, usage_start date, usage_end date)
title (id serial, line_num integer, title_type char(1), language char(2), title varchar(128))
In the Item class, I want to have a Map mapping from <line_num, title_type, language> -> item_title for active titles.
First, I created an embedded class called TitleClassifier to store the three pieces of title information: line_num, title type and language and use this in the Title class. Next, in the Item class, I define this field:
Code:
@OneToMany(mappedBy = "item")
@Where(clause = "active = 'true'")
private Map<TitleClassifier, ItemTitle> activeTitles;
When I test this, I get an exception because the generated query is looking in the item_title table for the line_num, title_type and language columns, which are in the title table, not the item_title table. I think this is happening because the Map "value" is of type ItemTitle and Hibernate is expecting the key values to come from this table as well.
Can I make this mapping this work or is it just too complicated?
Thanks
Andrew