Hibernate“无法获取下一个序列值”甲骨文

发布于 2024-11-02 11:58:03 字数 838 浏览 1 评论 0原文

当我尝试使用 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');

在 Oracle SQL Developer 中,插入文章(标题)值('asdfaf'); 效果很好。

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

i get this error could not get next sequence value when I try to save this Entity with 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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無處可尋 2024-11-09 11:58:03

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

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

仙女 2024-11-09 11:58:03

我知道有很多导致这个例外的原因。也许您可以检查问题并向我提供有关您的问题的更多详细信息:

  • 检查“hibernate.dialect”是否设置为 Oracle?
  • 序列权限是否正确(架构、选择等)?
  • 表后面是否有一些触发器并抛出 plsql 错误?
  • 其他一些可能会破坏插入的plsql?
  • 交易中断了吗?
  • 在调用 create 之前是否存在异常(有时是无声的)(例如陈旧状态或退出),以便事务被标记为回滚?
  • 异常之前是否有连接错误?
  • 该实体是否可能已经附加(检查包含)?
  • 您是否使用 spring 或其他可以添加异常解析器或转换器的框架?
  • 您使用的是哪个版本的oracle数据库? 10还是11?使用的驱动程序是否正确?
  • 之前是否有 findSingle 调用不返回任何值?

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?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文