Reputation: 1651
I'm using Hibernate framework the XML way, in a Spring Boot project. I chose PostgreSQL as DBMS. I've set the configuration files but I'm getting "could not extract ResultSet" message whenever I try to insert data. The exception i;m getting is
org.postgresql.util.PSQLException: ERROR: relation "employees" does not exist
I tested connection with Intellij and it was fine. I think something is wrong with my hbm file.
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQL94Dialect</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/MyDB</property>
<property name="connection.username">postgres</property>
<property name="connection.password"></property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<mapping resource="employees.hbm.xml" />
</session-factory>
employees.hbm.xml
<?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="com.company.entities.Employee" table="Employees" schema="public" >
<id name="eid" type = "int" column = "eid">
<generator class="increment"/>
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<property name="salary" column="salary" type="java.lang.Double" />
</class>
</hibernate-mapping>
EmployeeDAO.java
@Repository
public class EmployeeDAO
{
static Session sessionObj;
private static SessionFactory buildSessionFactory()
{
return new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
}
public void insertEmp(List<Employee> allEmployees)
{
sessionObj = buildSessionFactory().openSession();
sessionObj.beginTransaction();
for (Employee emp: allEmployees)
{
sessionObj.save(prod);
}
sessionObj.getTransaction().commit();
if(sessionObj != null)
{
sessionObj.close();
}
}
}
Upvotes: 0
Views: 741
Reputation: 2769
the error message mentions "employee" whereas in your mapping, you are talking about "Employee" ... i think it might be a case issue:
https://blog.xojo.com/2016/09/28/about-postgresql-case-sensitivity/
employees.hbm.xml file needs to change from
<class name="com.company.entities.Employee" table="Employees" schema="public" >
to
<class name="com.company.entities.Employee" table="`Employees`" schema="public" >
Upvotes: 1