Note that there are some explanatory texts on larger screens.

plurals
  1. POMissing sequence or table: hibernate_sequence
    primarykey
    data
    text
    <p>I am new to hibernate and postgres. Actually I am trying to map potgres database using Hibernate. This is my table stucture in postgresql</p> <pre><code>CREATE TABLE employee ( id serial NOT NULL, firstname character varying(20), lastname character varying(20), birth_date date, cell_phone character varying(15), CONSTRAINT employee_pkey PRIMARY KEY (id ) ) </code></pre> <p>I am trying to add a record to the database using the following code</p> <pre><code> System.out.println("******* WRITE *******"); Employee empl = new Employee("Jack", "Bauer", new Date(System.currentTimeMillis()), "911"); empl = save(empl); //This is the save function private static Employee save(Employee employee) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); int id = (Integer) session.save(employee); employee.setId(id); session.getTransaction().commit(); session.close(); return employee; } </code></pre> <p>When I execute the code I am getting the following error</p> <pre><code>org.hibernate.HibernateException: Missing sequence or table: hibernate_sequence Exception in thread "main" java.lang.ExceptionInInitializerError at org.tcs.com.Hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:18) at org.tcs.com.Hibernate.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:8) at org.tcs.com.Hibernate.MainApp.list(MainApp.java:51) at org.tcs.com.Hibernate.MainApp.main(MainApp.java:17) Caused by: org.hibernate.HibernateException: Missing sequence or table: hibernate_sequence at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1282) at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155) at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:498) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778) at org.tcs.com.Hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:15) ... 3 more </code></pre> <p>I have the sequence called "employee_id_seq" in my database. But I dont know why the database is looking for hibernate_seq. Could someone explain the error and the reason.</p> <p>Thanks in advance!</p> <p><strong>Added info</strong></p> <p>This is my employee class</p> <pre><code>import java.sql.Date; public class Employee { private int id; private String firstname; private String lastname; private Date birthDate; private String cellphone; public Employee() { } public Employee(String firstname, String lastname, Date birthdate, String phone) { this.firstname = firstname; this.lastname = lastname; this.birthDate = birthdate; this.cellphone = phone; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } public String getCellphone() { return cellphone; } public void setCellphone(String cellphone) { this.cellphone = cellphone; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload