I am new to hibernate and postgres. Actually I am trying to map potgres database using Hibernate. This is my table stucture in postgresql
CREATE TABLE employ
You haven't posted the important bit: the Employee
class.
But my guess is that your Employee class is using @GeneratedValue()
without specifying the sequence to use. So, Hibernate uses its default name: hibernate_sequence.
You can supply a sequence name as part of the GeneratedValue annotation. eg.
@GeneratedValue(strategy=SEQUENCE, generator="employee_id_seq")
In your domain or Model object annotate the id field as below and it should work. For me the GenerationType.AUTO failed
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
If you don't use annotation you should change YourClass.hbm.xml file.
Your ID section should be:
<id name="id" type="int" column="id">
<generator class="sequence">
<param name="sequence">employee_id_seq</param>
</generator>
</id>
File sample:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="id" type="int" column="id">
<generator class="sequence">
<param name="sequence">employee_id_seq</param>
</generator>
</id>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="salary" column="salary" type="int"/>
</class>
</hibernate-mapping>
You can do two things. One is to just manually create a blank hibernate_sequence table postgresql. Two, most likely there is a conflict with the user account permissions not allowing grails to create that table.
If you encounter this with Spring Boot or Spring boot/Hibernate Migration then potentially you can try the following
https://mkyong.com/spring-boot/spring-boot-mysql-table-db_name-hibernate_sequence-doesnt-exist/
Simple solution :
create hibernate_sequence table as :
"create sequence <schema>.hibernate_sequence"