I have two tables ActivityType and ActivitySubType with ManyToMany relationship with each other. So I have a another table Activity_Main_Sub_Type which has two columns
(!) ActivityTypeId (2) ActivitySubTypeId
There is another table Activity which has reference to both ActivityTypeId and ActivitySubTypeId as foreign keys. Now I had generated these tables using Hibernate schema update. Now I want to delete Activity_Main_Sub_Type table and populate it again. I am not able to do that. I get foreign key constraint error on Activity table. When I looked in to the table I saw that there are two foreign key reference from table Activity_Main_Sub_Type. I am not sure how did I get this? Can any body suggest me if I am missing anything. Is there any way I can update my table and add new data.
You should have only two entities defined ActivityType and ActivitySubType (make sure the mappedBy and join columns are correct.). Since you are generating schema from entity definition, hbmtoddl will create the mapping table Activity_Type_Activity_Sub_Type. This will have the foreign keys to ActivityType and ActivitySubType. Third entity Activity is not needed here.
But Activity is another class which is using ActivityType and subtype. For example in my application user can create an activity of particular type and under that sub type. So I need to save that in database as a record. But I am not sure why Activity table has reference to mapping table Activity_Type_Activity_Sub_Type.
Does the entity Activity, has any other attributes other than ActivityTypeId and ActivitySubTypeId. If no, the entity Activity is similar to the auto generated mapping table Activity_Type_Activity_Sub_Type.
T Mishra wrote:Does the entity Activity, has any other attributes other than ActivityTypeId and ActivitySubTypeId. If no, the entity Activity is similar to the auto generated mapping table Activity_Type_Activity_Sub_Type.
Yes, It has other attributes as well. Also some other references.