Hi,
Hibernate version: 3.1.3
I have the following database model :
Code:
create table ingredients (
id integer not null,
name VARCHAR(255),
primary key (id)
)
create table recipes (
id integer not null,
name VARCHAR(255),
primary key (id)
)
create table cooked_ingredients (
recipe_id integer not null,
ingredient_id integer not null,
quantity float
)
alter table cooked_ingredients
add constraint fk_cooked_ingredients_recipe foreign key (recipe_id) references recipes
alter table cooked_ingredients
add constraint fk_cooked_ingredients_ingredient foreign key (ingredient_id) references ingredients
I would like to generate a mapping for these Java beans :
Code:
Ingredient {
private int id;
private String name;
}
CookedIngredient extends Ingredient {
private double quantity;
}
Recipe {
private int id;
String name;
Collection<CookedIngredient> ingredients;
}
The association between an Ingredient and a Recipe is a many-to-many association.
I know how to do an inheritance mapping with the <sub-class /> tag. And I know how to do an association (many-to-many) mapping with the <set><many-to-many /></set> tags. But I'm unable to do the mapping for the above sample.
Is my wanted mapping is possible ? And how can I do it please ?
Thx,