简体   繁体   English

ORA-02289序列不存在,但是数据库中存在序列

[英]ORA-02289: sequence does not exist, however sequence is aleady exist in database

I have been working on a java spring project, in which I have created a class whose sole purpose is to record the request body for every service have been called in the database. 我一直在研究java spring项目,在其中创建了一个类,其唯一目的是记录数据库中已调用的每个服务的请求主体。

The table contains a primary key named as transaction_id and other fields which is required to records the request. 该表包含一个名为transaction_id的主键以及记录请求的其他字段。 The model of the tables in Java looks like: 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;
}

In the database, I have created one sequence named as id_seq2 whereas id_seq1 already exists: 在数据库中,我创建了一个名为id_seq2的序列,而id_seq1已经存在:

Newly created id_seq2: 新创建的id_seq2:

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

Already exists id_seq1 dll: 已经存在id_seq1 dll:

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

case 1: 情况1:

whenever I trigger any services from the postman with below sequence generator with sequence name id_seq2 I get the error "sequence does not exist". 每当我使用下面的序列生成器(序列名称为id_seq2)从邮递员触发任何服务时,都会出现错误“序列不存在”。 However, the sequence is already there in DB. 但是,该序列已存在于DB中。

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

The project war file is successfully deployed on the server. 项目war文件已成功部署在服务器上。 After that whenever the service is trigger from the postman following error is occurred: 此后,每当邮递员触发服务时,就会发生以下错误:

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)

case 2: 情况2:

Afterward for testing purpose, I have change the sequence name from id_seq2 to id_seq1 and redeployed the code on server and surprisely I am able to trigger the service sucessfully. 之后出于测试目的,我将序列名称从id_seq2更改为id_seq1并在服务器上重新部署了代码,令人惊讶的是,我能够成功触发该服务。

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

Output: 输出:

{ {

"responseCode": "0" “ responseCode”:“ 0”

} }

I have no idea where I made a mistake as in my point of view, there is something which I have missed in sequence generator. 我不知道我在哪里犯了错误,因为从我的角度来看,序列生成器中缺少一些东西。

In your case the sequence must exist in the same schema as the schema/user you log into. 在您的情况下,该序列必须与您登录的模式/用户位于相同的模式中。 If you login as an other user then you can try this rather rude solution. 如果您以其他用户身份登录,则可以尝试这个相当粗鲁的解决方案。

create public synonym "id_seq2" for "id_seq2";
grant select on "id_seq2" to public;

Or try to figure out what privs and synonyms you have om "id_seq1" and apply that to "id_seq2" as well. 或者尝试找出“ id_seq1”中有哪些priv和同义词,并将其也应用于“ id_seq2”。

A missing sequence that exists may be caused from two reasons: 存在的序列缺失可能是由于两个原因引起的:

1) the sequence exists in a different schema that you are connected with 1)序列存在于与您连接的不同架构中

in this case you must reference schema_owner . 在这种情况下,您必须引用schema_owner schema_name

2) the sequence exists in a different schema and you have no privileges to access it 2)序列存在于其他架构中,您无权访问它

You should first realize in which schema the existing sequence is created. 您首先应该意识到现有序列是在哪个架构中创建的。

You can verify it with the following query (substitute the sequence name as required) 您可以通过以下查询进行验证(根据需要替换序列名称)

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

If you see nothing, the sequence either doesn't exists or it exists in a different schema as you are connected with and you have no SELECT priviledge on it. 如果您什么都看不到,则说明该序列要么不存在,要么在您连接时存在于其他模式中,并且没有SELECT特权。

In case you use a sequence from a different schema than your Hibernate connection user (which is rather a usual case), you must use the schema parameter of the @SequenceGenerator annotation and pass the propper schema owner. 如果您使用的模式来自与Hibernate连接用户不同的模式(这是很常见的情况),则必须使用@SequenceGenerator批注的schema参数并传递适当的模式所有者。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ORA-02289序列不存在,找不到我的错误 - ORA-02289: sequence does not exist, cannot find my error JPA(休眠):“ ORA-02289序列不存在”,但确实存在 - JPA (Hibernate): “ORA-02289 Sequence does not exist”, but it does ORA-02289: 序列不存在,休眠错误 - ORA-02289: sequence does not exist, error in hibernbate ORA-02289:将Hibernate 3升级到休眠4时序列不存在 - ORA-02289: sequence does not exist when upgrade Hibernate 3 to hibernate 4 线程“主” org.hibernate.exception.SQLGrammarException中的异常:ORA-02289:序列不存在 - Exception in thread “main” org.hibernate.exception.SQLGrammarException: ORA-02289: sequence does not exist 错误:ORA-02289:序列不存在 - org.hibernate.exception.SQLGrammarException:无法提取 ResultSet - ERROR: ORA-02289: sequence does not exist - org.hibernate.exception.SQLGrammarException: could not extract ResultSet ORA-02289: 序列不存在 - 当使用 Spring 数据 JPA 和 Spring 启动时 - ORA-02289: sequence does not exist - when using Spring Data JPA with Spring boot 嵌套的异常是org.hibernate.exception.SQLGrammarException:ORA-02289:序列不存在 - nested exception is org.hibernate.exception.SQLGrammarException: ORA-02289: sequence does not exist ORA-02289: 序列不存在 - 选择键或将结果设置到参数 object 时出错 - ORA-02289: sequence does not exist - Error selecting key or setting result to parameter object spring数据JPA无法创建主键,出现此错误SQL错误:2289,SQLState:42000 ORA-02289:序列不存在 - spring data jpa unable to create primary key getting this error SQL Error: 2289, SQLState: 42000 ORA-02289: sequence does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM