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

前端 未结 2 1119
无人共我
无人共我 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:49

    The AUTO strategy is an alias for NATIVE if your database supports it, or SEQUENCE if your database supports it, or TABLE if your database doesn't support any of those.

    So if the database doesn't support NATIVE and SEQUENCE, then you need to create the table that EclipseLink uses to generate IDs.

    With MySQL, NATIVE should be supported. You need to make the ID column an auto_increment column, though. Make sure to configure the appropriate DatabasePlatform as well.

    0 讨论(0)
  • 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 )

    0 讨论(0)
提交回复
热议问题