June 2018
Intermediate to advanced
408 pages
11h 23m
English
Most of the time, we will want to use database sequencing for our table primary key. In order to do so, we know that we need to add the generator attribute in the @GeneratedValue annotation on our entity. The @GeneratedValue annotation allows us to define a strategy for our primary key.
The following is the code snippet that we add in our entity to set database sequencing for our primary key:
@Id@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "accountSequence")private Integer id;
Here, we thought that accountSequence was the database sequence name provided to the generator; however, when the application runs, it gives an exception. To solve this exception, we annotate our entity with @SequenceGenerator ...
Read now
Unlock full access