java - JPA: how to set up key for historizing entities -


within jpa in spring boot / spring data, want set entity class.

the business requirement historize processing of documents exist once per year each.

the processing performed in bulk: documents processed together: there one processingtimestamp documents in database each processing sequence.

later on, want access processed document, keep processed documents reference.

i see following alternatives:

  1. use composite key

    @id private string documentid;  @id private string yearofdocumentcreation;  @id private java.sql.timestamp processingtimestamp; 
  2. use auto generated key

    @id @generatedvalue(strategy = generationtype.auto) private long id;  private string documentid;  private string yearofdocumentcreation  private java.sql.timestamp processingtimestamp; 

which alternative better/best practise regarding

  1. handling (e.g. storing list of documents bulk read before database , avoiding duplicates in database)
  2. performance

or miss other alternatives/aspects?

i recommend using single long primary key, if need make foreign key table. avoid dublicates can make unique constraint on 3 required columns.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -