4

I'm working with JPA entities.

I created a new one like this:

@Entity
public class Entity {
    @Id
    @GeneratedValue(generator = "Entity_Sequence", strategy = GenerationType.SEQUENCE)
    @SequenceGenerator(name = "Entity_Sequence", sequenceName = "Entity_Seq")
    private Long id;

    // ... other fields
}

Generated SQL I used to create DB Objects:

CREATE SEQUENCE ENTITY_SEQ START WITH 1 INCREMENT BY 50;

CREATE TABLE ENTITY (
  ID     NUMBER(19, 0) NOT NULL,
  -- ... other fields
  PRIMARY KEY (ID)
);

Now, I am able to query the nextval of the sequence from SQL Developer and from IntelliJ. But when I try to persist an entity from code, Hibernate throws the following exception:

15:21:11,022 INFO  [stdout] (EJB default - 2) Hibernate: select ENTITY_SEQ.nextval from dual
15:21:11,037 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 2) SQL Error: 2289, SQLState: 42000
15:21:11,037 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 2) ORA-02289: Sequence ist nicht vorhanden.

("Sequence ist nicht vorhanden" translates to "Sequence does not exist".)

Why is Hibernate not able to find the sequence while I am?

EDIT 1 (12-01):
I tried the suggested answer from Olivier, but the error is still the same.

EDIT 2 (12-01):
Since Olivier deleted his answer, he suggested I move the @SequenceGenerator annotation to the class.

8
  • Are you sure that hibernate connects to the correct database? Commented Dec 1, 2017 at 14:43
  • @OlivierGrégoire Yes, all other entities work (which I have created a year ago, but have the same structure) Commented Dec 1, 2017 at 14:46
  • Usually Oracle is not case-sensitive, but try to put your table name in uppercase in your entity as well: sequenceName = "ENTITY_SEQ". Commented Dec 1, 2017 at 14:48
  • @OlivierGrégoire I've also tried that, still nothing. Also I use a custom NamingStrategy which transforms names to UPPER_CASE already. Commented Dec 1, 2017 at 14:57
  • Do you have several users for that database? Is it possible that you created the sequence and table with a specific user (let's call this user "admin") but are using hibernate with another user (let's call this user "app")? Then, that some scripts gives visibility to the tables to "app", but doesn't do the same with sequences? Commented Dec 1, 2017 at 14:58

2 Answers 2

1

I found the error: It was my local setup, so nothing useful to tell you, just check your setup.

I was "configuring" my server in files that aren't actually used by the server, and thus showed no effect.

Sign up to request clarification or add additional context in comments.

Comments

0

there could be many errors. Are there some more informations about your project configuration available?

Greetz Dennis

1 Comment

Hey. Welcome to stackoverflow! Could you please ask questions as comments? Refer to this guide to see how to write a good answer stackoverflow.com/help/how-to-answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.