I have jpa annotated entity class like:
@Configurable
@Entity
@Table(name="PLAYERS")
public class Player
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID")
private Integer id;
@Column(name="NAME")
private String name;
@PersistenceContext
public transient EntityManager entityManager;
...
}
This has worked fine until I decided to create table with backuped yaml data using syntax like:
createNativeQuery("INSERT INTO PLAYERS ...")
After successful creation when I try to create an entity with:
Player player = new Player();
player.setName("new player");
player.persist();
i got error:
SQL Error: -1, SQLState: 23505
related to the duplication of primary_keys, because id generated for new entity = 1 (the same as row retrived from backuped data). Of course I can retrive data from backup file by using jpa/java syntax but in this case I have no control over primary keys of inserted data etc. How to solve this problem ? Is there any way to update id_generator after the insertion of backuped data ?