0

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, e.g. User entities will be in a Long type sequentially starting from zero, and the same with the Profile entities to start with 0 too.

Nick Johnson
  • 98,961
  • 16
  • 125
  • 196
quarks
  • 29,080
  • 65
  • 239
  • 450

2 Answers2

0

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

deepmoteria
  • 1,761
  • 2
  • 15
  • 20
  • I forgot to define that I am using app engine to store data, on its Big table, is your answer still applicable to app engine? – quarks Apr 18 '12 at 07:06
  • Sorry no idea about appengine but that is confirm that the sequences will be independent. – deepmoteria Apr 18 '12 at 07:10
  • I just confirmed with my code unit test that each type of entity have its own sequence of autogenerated id, that start with 1 – quarks Apr 18 '12 at 15:45
0

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.

Nick Johnson
  • 98,961
  • 16
  • 125
  • 196
  • What do you mean "which may overlap", do you mean for each entity type ID's may overlap, or for every Entity there is ID sequence independent of other entity types? – quarks Apr 19 '12 at 12:13
  • @xybrek I mean that you can have a User with ID 1, and a Profile with ID 1. – Nick Johnson Apr 19 '12 at 13:09