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:
use composite key
@id private string documentid; @id private string yearofdocumentcreation; @id private java.sql.timestamp processingtimestamp;
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
- handling (e.g. storing list of documents bulk read before database , avoiding duplicates in database)
- 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
Post a Comment