[英]Best practice for database dictionary in java
Is there a "canonical" way to represent a dictionary in - maintained through java persistence - database? 是否存在“规范”方式来表示字典-通过Java持久性维护-数据库?
Lets say I have a table of people and there is a column "profession". 可以说我有一张人桌,有一列“专业”。
Set of professions is restricted but can be extended. 专业设置是受限制的,但可以扩展。 Some professions have some special meanings for a system, like a military, or a doctor. 有些职业对系统有一些特殊的含义,例如军队或医生。
First solution is short and easy. 第一个解决方案简短易行。 But in that case, database without application has no integrity. 但是在那种情况下,没有应用程序的数据库就没有完整性。 Is the second "legacy" way inappropriate? 第二种“传统”方式不合适吗?
I think you have identified the pros and cons of the two approaches. 我认为您已经确定了这两种方法的利弊。 It is really up to you to decide which is better ... for your specific application. 真正由您决定哪个对您的特定应用更好。
Or to put it another way, "best practice" depends on your application's real requirements. 换句话说,“最佳实践”取决于应用程序的实际需求。
You could use a combination of both schemes: 您可以使用两种方案的组合:
Have a Professions
table with a single primary key , the name of the profession. 有一个带有单个主键 (专业名称)的Professions
表。
Have a People
table with a foreign key constraint in the profession
column. 有一个People
跟在一个外键约束表profession
列。
Using a string for a primary/foreign key would affect update performance, but it makes each row in People
self-contained, which benefits retrieval operations. 使用字符串作为主键/外键会影响更新性能,但是会使People
每一行都是独立的,这有利于检索操作。 Therefore, this alternative might be possible, unless a benchmark says otherwise. 因此,除非基准另有说明,否则这种替代方法是可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.