简体   繁体   中英

Id generation for stored entities (App engine)

If I have a entity defined like this that is stored in App engine's Big Table:

@Entity
@Table(name = "users")
public class User implements Serializable{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id; 
    private String username; 
    private String password;
    private String encryptedPassword;
    private String creationDate;
    private String modificationDate;
    private Boolean validated;

        // Code omitted
}

And if I have another entity with another table annotation say, @Table(name = "profile") would each entity Id's independent to each other. For example there is a User entity which have an id that is 0 and a Profile entity having a id 0.

I mean since entities are stored in a "big table" then sequential Id's will be assigned for all entities stored. Does adding such annotation solve this issue for entities to have independent sequence of id's?

What I'm trying to accomplish is that each entity to have its own Id starting from 0 to n, that each entity type to have its own sequence, eg User entities will be in a Long type sequentially starting from zero, and the same with the Profile entities to start with 0 too.

Yes no matter any number of entity you have, the autogenerated id or sequence always are independent, and in case of PostgreSQL if you take the datatype as bigint than you have to manually make a sequence in the database but if you take it as a bigserial than no need to make sequence explicitly in the db server for that table. Enjoy.........

No, all kinds have their own ID sequences, which may overlap. You could use the allocate_ids API to allocate unique IDs, but note that this still won't allow you to query for entities without knowing their kind (which I presume is why you want to do this), since you'd have to query every kind to find the one that contains your ID.

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