'Add @GeneratedValue on a later point, when data in table is already present

An entity which has ID but the data in corresponding table was added manually, for this reason @GeneratedValue annotation was never added. Now I need to create records in this table through code and want my ID to be auto-incremented. On adding @Id @GeneratedValue(strategy = GenerationType.AUTO) Integer id; The exception I get is:

java.sql.SQLException: Field 'id' doesn't have a default value

Is there a way to make this work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source