java - Hibernate - What primary key should I use in a one to many relationship without an ID on the child table -


In a very simple way, I am trying to create the following structure:

  Post ID (pk) name content table tag post_id (name to post id) the name   

so that a post can have several tags, but the tag does not have a primary ID. (The primary key so far will be the overall post_ID + name)

Now what I want to know is that it is bad behavior (leaving the id column in the tag table) and what happens when using hibernate Potential value to use as the primary key for the tag table.

In a normalized, every line in the database has a primary key; it should be

post_id feels like a foreign key that should refer to the table of the post id primary key.

I do not care much for this design; There may be many tags in a post; A tag can be applied to several posts, it should be several-to-many designs with the host table.

  Create a table post (id int do not auto_interment, text varchar (140), primary key ID); Create table tag (id int null auto_increment, name varchar (80) not tap, primary key ID); Create a table post_tag (post_ id int, tag_ id int, primary key (post_id, tag_id), foreign key (post_id) reference (id), foreign key (tag_id) reference tag (id);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -