I'm focusing on a cafe or restaurant application using Hibernate. I've several organizations like Pizza, Beverage, Pasta etc.
I would like those to be endured to various tables but have primary secrets which are unique of all. i.e if I only say itemId 4 it ought to be sufficient to recognize the food products available.
Any idea how to get it done men?
I'd should you prefer a solution using Hibernate annotations. :-
Use a db sequence and then for any of the organizations may use this sequence to create their Id.
An UUID could be unique for those tables, however, you will not have the ability pick which the table is dependant on the id only.
To tell the truth, this really is a little strange requirement. But when you actually insist upon it, you can just prefix the table/entity title towards the primary key. For your you'd require a custom generator. See this question.
You should use inheritance. Possess a base entity
@Inheritance strategy set to table-per-class after which
Pizza. When the fields don't differ much you utilize even single-table strategy having a discriminator column. And when your entity types will probably grow, you can just have one
Item having a column
I believe you haven't got the analysis quite correct. Should you look how you'll use thee organizations you mention I believe you'll also have an entity like order which will contain a number of these, also each one of these organizations will have some similarity all of them can be viewed as a subclass of 'menu item' as every one has some common characteristics e.g. cost and may be used in the same manner e.g. incorporated within an order.
You can try section 5.1.6 in Hibernate core documentation regarding how you can implement various methods of mapping the OO modle to some table or several tables. Observe that Table per class strategy and 10.1.5. Table per concrete class gives you your present table setup but you have to have the ability to create the key that you simply sitting MySQL canrrrt do easily. However think you will notice that you will find common qualities that needs to be around the base class and thus another type of the mapping could be needed and also you finish track of a food selection table which can certainly possess a produced id.
To be sure with Mark, it appears something similar to a table per subclass would match your design and will need an id across multiple products. Also observe that getting your products in multiple table with no common parent table can lead to some trouble when you're in the necessity of a FK of these products.