O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unknown Id.generator exception

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required