I am trying to save below entity in Oracle database.
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Book {
@Id
@GeneratedValue
private int id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Book book1 = new Book();
book1.setName("Sample");
session.save(book1);
But Hibernate is generating below exception stack trace.
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
Also I am seeing Hibernate is trying to run below query to fetch value from sequence, which is when the exception is getting generated.
Hibernate: select hibernate_sequence.nextval from dual
Table Schema:
CREATE TABLE BOOK(
ID INTEGER,
NAME VARCHAR2(50)
);
ALTER TABLE BOOK ADD PRIMARY KEY(ID);
@GeneratedValue(strategy = GenerationType.IDENTITY)to youridmember variable and try? Also, you should declare member variables in Entity class likeprivate Integer id;ratherprivate int id;.Bookis mapped to ? Also, if you could post the table schema it would be helpfulidso hibernate is complaining.