[英]Do i need to make sql tables using constraint to work with hibernate
I am using hibernate annotations with spring MVC. 我在Spring MVC中使用休眠注释。
Now i always create table using GUI editor like SQLYOG or phpmyadmin. 现在,我总是使用GUI编辑器(如SQLYOG或phpmyadmin)创建表。 So i just create table with columns and even if i have some tables primaray key in other table , i just make that column with name like
所以我只创建带有列的表,即使我在其他表中有一些表primaray键,我也只用名称命名该列
Person ---id--name--age
SUbject------person_id----description
So i made those tables using GUI with mentioning anything about foreign key etc. 因此,我使用GUI制作了这些表,并提及了有关外键的任何内容。
There is option in GUI editor ti make it primary kay and Auto increment so it usually works till now. GUI编辑器中有一个选项ti使它成为主要功能和自动递增功能,因此它通常可以使用到现在。
But i want to know that in Hibernate do i need to make tables with proper sql command . 但是我想知道在Hibernate中我是否需要使用适当的sql命令制作表。 i mean do i need to mention which table is primary key and which is foreign key
我的意思是我需要提到哪个表是主键,哪个是外键
or hibernate annotations are enough for that 或休眠注释就足够了
Hibernate will work just fine as long as your annotations are correct. 只要您的注释正确,Hibernate就能正常工作。
But from a database design point of view I strongly suggest that you create at least the primary key and foreign key constraints. 但是从数据库设计的角度来看,我强烈建议您至少创建主键和外键约束。
Your queries will run much faster if you create the primary keys. 如果创建主键,查询将运行得更快。 You can improve performance a little more by creating other kinds of indexes to.
您可以通过创建其他类型的索引来进一步提高性能。
PHPMyAdmin is perfectly able to create primary keys for you, as well as every other index types there is in mysql. PHPMyAdmin完全能够为您创建主键,以及mysql中存在的所有其他索引类型。 There's no need to write your creation code by hand.
无需手动编写您的创建代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.