I have a tiered set of model objects:
Restaurants have one ore more Menus that have one or more Items.
I've expressed the Restaurant to Menu relationship as follows:
<at>Entity
public class Restaurant extends ModelBase {
<at>OneToMany(mappedBy="restaurant")
private List<Menu> menus;
...
}
<at>Entity
<at>Table (
name="MENU",
uniqueConstraints=<at>UniqueConstraint(columnNames={"NAME",
"RESTAURANT_ID"})
)
public class Menu extends ModelBase {
<at>ManyToOne(optional=false)
<at>JoinColumn(name="RESTAURANT_ID")
private Restaurant restaurant;
...
private String name;
...
}
I'm curious about a couple of issues:
1. I want to make sure that when a menu is created *for a restaurant*, not
more than one menu *with the same name *can be created for that restaurant.
Is controlling this with the <at>UniqueContraint the right way to go?
2. Do I need to create a Restaurant object *in* the Menu? What I want to
ensure is that when a menu is created for a restaurant, I have a way of
knowing which menu was created for which restaurant. Should I just have an
"int restaurantId" parameter in place of the Restaurant object? If so, how
do I ensure the constraint in point #1 holds true?
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users