Hibernate“无法获得下一个序列值”oracle

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5722295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:24:34  来源:igfitidea点击:

Hibernate "could not get next sequence value" oracle

oraclehibernatesequence

提问by Evgeni Dimitrov

i get this error could not get next sequence valuewhen I try to save this Entity with Hibernate:

could not get next sequence value当我尝试使用 Hibernate 保存此实体时出现此错误:

package beans;

import javax.persistence.*;

@Entity
@Table(schema = "EVGENY")
public class Article {
    @SequenceGenerator(name="ArticleGen", sequenceName="ARTICLESEC")
    @Id
    @GeneratedValue(generator= "ArticleGen")
    private int id;
    @Column(name="title")
    private String title;
    @Column(name="text")
    private String text;
    @Column(name="postat")
    private String postat;
    @ManyToOne
    @JoinColumn(name = "USER_ID")
    private UserAcc user;

    public Article(){
    }

    Get Set...      

}

insert into article (title) values('asdfaf');

in Oracle SQL Developer this insert into article (title) values('asdfaf');works well.

在 Oracle SQL Developer 中,这insert into article (title) values('asdfaf');很有效。

if i set id variable explicitly ( Article a = new Article();a.setId(3);) everything is OK. I double checked the name of the sequence.

如果我显式设置 id 变量 ( Article a = new Article();a.setId(3);) 一切正常。我仔细检查了序列的名称。

回答by Diallo

Check user permissions on the sequence. Most of the time it is grant issue

检查用户对序列的权限。大多数时候是拨款问题

回答by Frank Szilinski

I know a lot of reasons to get this exception. Maybe you can check the questions and give me some more details about your problem:

我知道有很多原因会导致此异常。也许您可以检查问题并提供有关您的问题的更多详细信息:

  • check if the 'hibernate.dialect' is set to Oracle?
  • permission on sequence ok (schemata, select etc.)?
  • is there some trigger behind the table and throwing plsql error?
  • some other plsql that could break the insert?
  • is the transaction broken?
  • was there an exception (sometimes silent) somwhere before the call of create (like stale state or out of bounce) so that transaction is marked for rollback?
  • is there a connection is erroneous error before exception?
  • is the entity maybe already attached (check with contains)?
  • do you use spring or another framework where you can add exception resolvers or translators?
  • which version of oracle database do you use? 10 or 11? and are the used drivers correct?
  • is there a findSingle call before that does not return any value?
  • 检查“hibernate.dialect”是否设置为 Oracle?
  • 对序列的许可(模式、选择等)?
  • 表后面是否有一些触发器并抛出 plsql 错误?
  • 其他一些可能破坏插入的plsql?
  • 交易被破坏了吗?
  • 在调用 create 之前的某个地方是否有异常(有时是无声的)(如陈旧状态或退出反弹),以便将事务标记为回滚?
  • 异常前是否有连接错误?
  • 实体是否可能已经附加(检查包含)?
  • 您是否使用 spring 或其他可以添加异常解析器或翻译器的框架?
  • 你用的是哪个版本的oracle数据库?10 还是 11?使用的驱动程序是否正确?
  • 在此之前是否有 findSingle 调用不返回任何值?