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.
sequenceName = "ENTITY_SEQ".