我试图让本教程(https://dzone.com/articles/spring-boot-jpa-hibernate-oracle)工作。
public class Player {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "player_Sequence")
@SequenceGenerator(name = "player_Sequence", sequenceName = "PLAYER_SEQ")
private Long id;
当我仅通过应用程序保存播放器对象时工作正常。但是每当我通过 import.sql 或手动导入数据时,生成的 ID 都会再次以“1”开头。
导入.sql
insert into Player (id, team_id, name, num, position) values(1,1,'Lionel Messi', 10, 'Forward');
insert into Player (id, team_id, name, num, position) values(2,1,'Andreas Inniesta', 8, 'Midfielder');
insert into Player (id, team_id, name, num, position) values(3,1,'Pique', 3, 'Defender');
当我使用 import.sql 运行示例代码时,我收到以下错误:
2018-09-12 10:59:21 DEBUG org.hibernate.SQL - select team0_.id as id1_1_0_, team0_.name as name2_1_0_, players1_.team_id as team_id5_0_1_, players1_.id as id1_0_1_, players1_.id as id1_0_2_, players1_.name as name2_0_2_, players1_.num as num3_0_2_, players1_.position as position4_0_2_, players1_.team_id as team_id5_0_2_ from team team0_ left outer join player players1_ on team0_.id=players1_.team_id where team0_.id=?
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [1]
2018-09-12 10:59:21 DEBUG org.hibernate.SQL - select player_seq.nextval from dual
2018-09-12 10:59:21 DEBUG org.hibernate.SQL - select player_seq.nextval from dual
2018-09-12 10:59:21 DEBUG org.hibernate.SQL - insert into player (name, num, position, team_id, id) values (?, ?, ?, ?, ?)
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - [Xavi Hernandeza]
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [INTEGER] - [60]
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [Midfielder]
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [BIGINT] - [1]
2018-09-12 10:59:21 TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [1]
2018-09-12 10:59:21 WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1, SQLState: 23000
2018-09-12 10:59:21 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00001: unique constraint (my_user_name.SYS_C007250) violated