org.hibernate.dialect.OracleDialect does not support identity key generation

前端 未结 7 1280
广开言路
广开言路 2020-12-14 19:25

I was trying to import a sample project in to eclipse and was facing the below given error up on running the application.

Caused by: org.hibernate.MappingExc         


        
7条回答
  •  遥遥无期
    2020-12-14 20:18

    You can use tell Hibernate to use a sequence to generate your ID's

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence")
    @SequenceGenerator(name = "id_Sequence", sequenceName = "ID_SEQ")
    private int id;
    

    This config basically tells Hibernate to use a database sequence called ID_SEQ to generate the ID's for this object. You can specify other sequences on other objects if you want other unique ID's or you can use the same sequence if you want globally unique ID's across your entire system.

    The only downside to this is that can't perform batch inserts (without some further config) because Hibernate needs to get the next sequence value from the database every time, and you can't use this config if you want to use a MySQL database, because they don't support sequences.

    If any of that doesn't make sense let me know and I'll explain it further.

提交回复
热议问题