简体   繁体   中英

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. 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

  • company 2_users

  • company N_users

but I want to have only one entity named user, can be possible to have this schema ?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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