首页 > 解决方案 > 当 SEQUENCE 不存在时,避免在第一次启动应用程序时出现异常

问题描述

我们使用序列来生成 ID。序列存储在数据库中自己的表中。

private static final String SEQ = "seq_gen_myentity";
    
@Id
@SequenceGenerator(name = SEQ, allocationSize = 50, initialValue = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQ)
private Long id;

当应用程序在具有空数据库的开发环境中首次启动时,具有序列的表不存在,并且服务器日志中的每个实体都出现以下异常:

[EL Warning]: 2021-03-05 09:23:20.345--ServerSession(1078388861)--Exception [EclipseLink-1002] (Eclipse Persistence Services - 2.7.1): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: SEQUENCE 'APP.SEQ_GEN_MYENTITY' does not exist.

在使用空数据库的应用程序第一次启动时,是否可以避免不存在序列的异常?

标签: javapostgresqljakarta-eeeclipselinkpayara

解决方案


推荐阅读