Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

Hibernate "could not get next sequence value" oracle

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.

Upvotes: 1

Views: 11305

Answers (2)

Diallo
Diallo

Reputation: 109

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

Upvotes: 1

Frank Szilinski
Frank Szilinski

Reputation: 550

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?

Upvotes: 0

Related Questions