简体   繁体   English

如何在JPA中使用前缀表名称

[英]How to use prefix table names with jpa

I'm using java play to make a web application and I'm having some trouble persisting data using ebeans and jpa annotations. 我正在使用Java Play制作一个Web应用程序,但是在使用ebeans和jpa注释持久化数据时遇到了一些麻烦。 I've searched a lot, and I'm a little confused, I think that this is something that should be common, I want to have tables named like this: 我已经搜索了很多东西,但有些困惑,我认为这应该很常见,我想使用这样的表命名:

  • company 1_users 公司1_用户

  • company 2_users 公司2_用户

  • company N_users 公司N_users

but I want to have only one entity named user, can be possible to have this schema ? 但我只想拥有一个名为user的实体,可以有这种架构吗?

I've searched about using one entity with multiple tables, about using table name prefixes and about using dynamic table name but I got nothing helpful. 我已经搜索过关于使用一个实体与多个表,关于使用表名前缀以及关于使用动态表名的搜索,但是我没有任何帮助。

Some ideas ?? 一些想法?

As @GlennLane said in comment, creating separate tables isn't good idea, instead use some field as a company id/discriminator. 正如@GlennLane在评论中所说,创建单独的表不是一个好主意,而是将某些字段用作公司ID /区分符。 You will save tons of nerves, and you won't need to update your code each time when new company joins the branch. 您将省去很多麻烦,并且不需要在新公司加入分支机构时每次都更新代码。

If you really want separate tables create separate model for each company, at least you won't mishmash that in code. 如果您真的想要单独的表为每个公司创建单独的模型,至少您不会在代码中混用该模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM