java - 当 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.
在使用空数据库的应用程序第一次启动时,是否可以避免不存在序列的异常?
解决方案
推荐阅读
- typescript - 扩展“通用”TypeScript 接口
- php - 在浏览器中预览文件而不是在 PHP 中下载
- amazon-web-services - 如何刷新 ElastiCache Memcached 集群?
- exceljs - 使用 ExcelJS 将图像导出到 Excel
- api - 使用 JWT 在 tcp 上托管 .net Core API
- php - 上传到我的 Laravel 6 应用程序的数据库表和公用文件夹的图像不起作用
- javascript - 在浏览器刷新时出现错误'TypeError:无法读取未定义的属性'id'
- c# - 在将 gridview 导出到 excel 时包含空格
- asp.net - 如何在 asp.net 中识别多个按钮 ID/值
- node.js - 使用 PhpStorm 和 npm start,我的 PC 变得非常缓慢