开发者

application specific seed data population

开发者 https://www.devze.com 2023-01-03 15:09 出处:网络
Env: JBoss, (h2, MySQl, postgres), JPA, Hibernate 3.3.x @Id @GeneratedValue(strategy = IDENTITY) private Integer key;

Env: JBoss, (h2, MySQl, postgres), JPA, Hibernate 3.3.x

@Id
@GeneratedValue(strategy = IDENTITY)
private Integer key;
  1. Currently our primary keys are created using the above annotation. We expect to support a large number of users (~million users), what key should be used. Should it be Integer or Long or should I use the unsigned versions of the above declarations.

  2. We have a j2ee application which needs to be populated with some seed data on installation. On purchase, the customer creates his own data on top of the application. We just want to make sure that there is enough room to ship, modify or add data for future releases. What would be the best mechanism to support this, we had looked at starting all table identifiers from a certain id (say 1000) but this mandates modifying primary key generation to have table or sequence based generators and we have around ~100 tables. We are not sure if this is the right strategy for this.

If we use a signed integer approach for the key, would it make sense to have the seed data as everything starti开发者_运维问答ng from 0 and below (i.e -ve numbers), so that all customer specific data will be available on 0 and above (i.e. +ve numbers)


Currently our primary keys are created using the above annotation. We expect to support a large number of users (~million users), what key should be used. Should it be Integer or Long or should I use the unsigned versions of the above declarations

From the Primitive Data Types of the Java tutorials:

int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead.

Up to you to see if it's safe :)

(...) We just want to make sure that there is enough room to ship, modify or add data for future releases. What would be the best mechanism to support this

I would test this with the mentioned database but using negative IDs for your seed data seems to be the safer solution (no possible collision). If it doesn't work (I think it should), then I believe a TABLE strategy would be the most portable solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消