How to point to other table's ID with hibernate?
The problem: let's say I have two tables Client, and Product, in which Client has its primary key and a column called products (that points to pk's in Product table)... ok, if I need products to point only one row, it's nice, but if I need it to point for... 1000 rows in Product table, the products column would have to be larger enough... but I can't predict this situation.
So, how could I design my table and how would I use hibernate with it, to achieve that "pointing" in a optmized and maybe "easy" wa开发者_如何学Goy.
NOTE: I excluded some columns of the "design" presented here, just to keep the simplicity.
NOTE 2: Each Client's row is unique, and only one Client is related to a Product's row, that is, Product will be of one client and of nobody else.
This is a many-to-one relationship. You can reference the Client from the Product table instead of the other way around.
Then, you can setup a one-to-many relationship in your hibernate mapping file. Here is a nice example about how to do that: http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-one-to-many-1.html
精彩评论