Amogh Amogh - 1 month ago 6
Java Question

Hibernate not creating foreign key constraint on MySQL

I am using Hibernate and MySQL when my mapping for table is done and when I look at my DB table its created successfully but their is no foreign key constraint but column is created.

When I try to insert record in child table and when I put id which not exist in parent table in foreign key column then also that row get inserted.

My table engine is innoDB.

If I change dialect to MS-SQL then table get created with foreign key constraint.

Answer

Sorry users,

I got issue with this actually my DBA not given permission for ALTER command.

so thats why, when an table with foreign Key is going to create first CREATE command is executed and then ALTER command is executed.

In my case CREATE command is executed successfully but ALTER command does not coz its dnt have permission.

Comments