简体   繁体   English

我是否需要使用约束使sql表与休眠一起使用

[英]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.

相关问题 我需要在Hibernate中手动创建关系表吗? - Do I need to manually create relation tables in Hibernate? 如果字段不为空,我是否需要与其他表连接以执行sql? - i need to do an sql with if then else to join tables if the field is not null? 我需要连接 4 个表来完成这个 SQL 查询还是有更简单的方法? - Will I need to do a join of 4 tables to fulfill this SQL query or is there a simpler method? 如何根据需要使COUNT工作? - How do I make COUNT work how I need it to? 如何使用 sql 向此表添加约束? - How do I add a constraint to this table using sql? 如何联接这3个表并使Select查询工作? - How do I join these 3 tables and make my Select query work? 我需要钻石关系来解决这个问题吗? - Do I need a diamond relationship to make this problem work? 我是否需要为文本中的每个关键字进行一次SQL查询? - Do I need to make one sql query for each keyword in a text? 卡住! 如何联接三个SQL表来回答这两个问题? 还是我不需要? - Stuck! How do I join three SQL tables to answer these two questions? Or do I not need to? 我的数据库中有4个表需要一个名为“类别”的字段。 我该如何进行这项工作? - 4 tables in my DB need a field called, “categories”. How can I make this work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM