gpt4 book ai didi

java - ORA-02289 : sequence does not exist, 但是序列已存在于数据库中

转载 作者:行者123 更新时间:2023-11-30 01:53:44 24 4
gpt4 key购买 nike

我一直在从事一个java spring项目,在该项目中我创建了一个类,其唯一目的是记录数据库中调用的每个服务的请求正文。

该表包含名为 transaction_id 的主键以及记录请求所需的其他字段。 Java 中的表模型如下所示:

@Entity
@Table(name="ForntEndLogHistory")
public class FrontEndLog {

@Id
@Column(name = "TRANSACTION_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@SequenceGenerator(name="id_generator", sequenceName = "id_seq2", allocationSize=1)
private Long transactionId;
private String request;
}

在数据库中,我创建了一个名为 id_seq2 的序列,而 id_seq1 已经存在:

新创建的 id_seq2:

CREATE SEQUENCE  "id_seq2"  MINVALUE 0 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;
commit;

已存在 id_seq1 dll:

CREATE SEQUENCE  "id_seq1"  MINVALUE 0 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 3467 NOCACHE  NOORDER  NOCYCLE ;

情况1:

每当我使用下面序列名称为 id_seq2 的序列生成器触发 postman 的任何服务时,我都会收到错误“序列不存在”。然而,该序列已经存在于数据库中。

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@SequenceGenerator(name="id_generator", sequenceName = "id_seq2", allocationSize=1)
private Long transactionId;

项目war文件已成功部署到服务器上。此后,每当 postman 触发服务时,就会发生以下错误:

org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:88)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:122)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:73)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:654)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:646)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:642)
at com.etisalat.mwallet.data.BaseDAO.save(BaseDAO.java:49)
at com.etisalat.mwallet.service.impl.LoggerService.logFrontEnd(LoggerService.java:59)
at com.etisalat.mwallet.service.impl.LoggerService.logFrontEndSuccess(LoggerService.java:29)
at com.etisalat.mwallet.rest.config.ResponseFilter.doFilter(ResponseFilter.java:180)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:774)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501)
at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:141)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)

情况2:

之后出于测试目的,我将序列名称从 id_seq2 更改为 id_seq1 并在服务器上重新部署代码,令人惊讶的是我能够成功触发服务。

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@SequenceGenerator(name="id_generator", sequenceName = "id_seq1", allocationSize=1)
private Long transactionId;

输出:

{

"responseCode": "0"

}

我不知道我在哪里犯了错误,因为在我看来,我在序列生成器中遗漏了一些东西。

最佳答案

存在缺失序列可能是由两个原因造成的:

1) 该序列存在于您所连接的不同架构中

在这种情况下,您必须引用schema_ownerschema_name

2) 该序列存在于不同的架构中并且您没有访问它的权限

您应该首先了解现有序列是在哪个架构中创建的。

您可以使用以下查询进行验证(根据需要替换序列名称)

select OWNER, OBJECT_NAME SEQUENCE_NAME
from all_objects where object_type = 'SEQUENCE'
and lower(object_name) = 'id_seq1';

如果您什么也没看到,则该序列要么不存在,要么存在于与您连接的不同模式中,并且您没有SELECT 权限。

如果您使用的序列与您的 Hibernate 连接用户不同(这是一种常见情况),则必须使用 schema @SequenceGenerator 注释的参数并传递适当的架构所有者。

关于java - ORA-02289 : sequence does not exist, 但是序列已存在于数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55178837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com