JPA EclipseLink DatabaseException: 'table foo.SEQUENCE doesn't exist'

前端 未结 2 1118
无人共我
无人共我 2021-01-01 01:12

I\'ve updated the question so that both tables now use auto-increment. Is perhaps the problem in persisting to the MESSAGES table a problem wi

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 01:53

    For mysql I would recommend you following:

    At you table messages at field id add declaration auto_increment:

    create table messages(
    ...
    id  int not null auto_increment,
    ...
    primary key (id)
    )
    

    At entity declaration use

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;   
    

    This talks to JPA use auto-increment feature of MySQL

    If it is not applicable (for example you may want to create related another entity in the same transaction) use TABLE strategy (for more details see http://www.objectdb.com/java/jpa/entity/generated )

提交回复
热议问题