简体   繁体   English

org.postgresql.util.PSQLException:错误:关系“ employee1”不存在

[英]org.postgresql.util.PSQLException: ERROR: relation “employee1” does not exist

I am very new in postgresql and hybernate and i am getting a problem in my first program, can you please help me out and thanks in advance. 我在postgresql和hybernate中是一个新手,在我的第一个程序中遇到问题,请您帮我一下,谢谢。

It prints comment 打印评论

Hibernate: 

/* insert testhybernate1.Employee

*/ insert 
    into
        employee1
        (ename, mobile, email, id) 
    values
        (?, ?, ?, ?)

and gives error:- 并给出错误:

org.postgresql.util.PSQLException: ERROR: relation "employee1" does not exist

I added 我加了

<property name="hibernate.hbm2ddl.auto">create</property> 

in my config file then that problem solved a new table created by hybernate with name Employee. 在我的配置文件中,然后该问题解决了由hybernate创建的名为Employee的新表。 But whatever i am inserting in this table through my program it is not updating in my database. 但是无论我通过程序在此表中插入什么内容,都不会在数据库中进行更新。 First question is why by adding 第一个问题是为什么要添加

<property name="hibernate.hbm2ddl.auto">create</property>

my problem solved and second question is why it is not updating in my database when i search through pgadmin? 我的问题解决了,第二个问题是为什么当我通过pgadmin搜索时它为什么不在数据库中更新?

In the database postgesql in public schema, i created a table employee1 with all column and table name in small letter.my mapping file "empmapping.hbm.xml" 在公共架构的数据库postgesql中,我创建了一个表employee1,其中所有列和表名都在小letter.my映射文件“ empmapping.hbm.xml”中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
<class name="testhybernate1.Employee" table="employee1">
<id name="id" column="id" type="integer">
<generator class="assigned"></generator>
</id>
<property name="ename" column="ename" type="string"></property>
<property name="mobile" column="mobile" type="long"></property>
<property name="email" column="email" type="string"></property>
</class>
</hibernate-mapping>

My config file "hypernate.cfg.xml" is given below:- 我的配置文件“ hypernate.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="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql:template1</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">Monu26@dmail</property>



<property name="hibernate.connection.autocommit">false</property>


<property name="hibernate.show_sql">true</property>


<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>



<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<mapping resource="empmapping.hbm.xml"></mapping>
</session-factory>


</hibernate-configuration>

my pogo class:- Employee.java 我的pogo类:-Employee.java

package testhybernate1;

import java.io.Serializable;

public class Employee implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private int id;
private String ename;
private long mobile;
private String email;

public Employee(){}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getEname() {
    return ename;
}

public void setEname(String ename) {
    this.ename = ename;
}

public long getMobile() {
    return mobile;
}

public void setMobile(long mobile) {
    this.mobile = mobile;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}



}

My application class Hybernate1.java 我的应用程序类Hybernate1.java

package testhybernate1;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Hybernate1 {

@SuppressWarnings("deprecation")
public static void main(String[] args) {
    System.out.println("starting........");
    Configuration cfg= new Configuration();
//  cfg.configure();
    try
    {
        cfg.configure();
    }
    catch(Exception e)
    {
        System.out.println("*** Exception while configuring:"+e);
    }
    SessionFactory sf=null;
    try
    {
    //  SessionFactory sf=new SessionFactory(cfg);
        sf=cfg.buildSessionFactory();
    }
    catch(Exception e)
    {
        System.out.println("exception in creating sessionfactory :"+e);

    }
    if(sf.equals(null))
    return;
    else
    {
        Session s=sf.openSession();

        Transaction tx = s.beginTransaction();

        Employee emp=new Employee();
        emp.setId(1);
        emp.setEname("Raghav");
        emp.setMobile(95899);
        emp.setEmail("k123@mail");


        Integer eid=(Integer)s.save(emp);
        //s.flush();
        tx.commit();
        s.close();
        System.out.println("emp id in database="+eid);

    }
    // TODO Auto-generated method stub

}

}

Sorry for the bug, 抱歉,该错误,

I got the answer, In my config file there should be 我得到了答案,在我的配置文件中应该有

<property name="hibernate.connection.url">jdbc:postgresql:postgres</property>

instead of 代替

<property name="hibernate.connection.url">jdbc:postgresql:template1</property>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决“Caused by: org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13”错误? - How to resolve "Caused by: org.postgresql.util.PSQLException: ERROR: relation "employee" does not exist Position: 13" error? org.postgresql.util.PSQLException:错误:关系“员工”不存在 Position:13 - org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13 org.postgresql.util.PSQLException:错误:关系“序列”不存在 - org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist org.postgresql.util.PSQLException:错误:关系“产品”不存在 - org.postgresql.util.PSQLException: ERROR: relation "products" does not exist org.postgresql.util.PSQLException:错误:关系“用户”不存在 - SpringBoot,Hibernate,Postgresql - org.postgresql.util.PSQLException: ERROR: relation "users" does not exist - SpringBoot, Hibernate, Postgresql org.postgresql.util.PSQLException:错误:关系“clienti_id_seq”不存在 - org.postgresql.util.PSQLException: ERROR: the relation“clienti_id_seq” does not exist org.postgresql.util.PSQLException:错误:关系不存在PreparedStatement.executeQuery() - org.postgresql.util.PSQLException : ERROR : relation does NOT exist PreparedStatement.executeQuery () org.postgresql.util.PSQLException:错误:关系“app_user”不存在 - org.postgresql.util.PSQLException: ERROR: relation "app_user" does not exist 嵌套异常是 org.postgresql.util.PSQLException:错误:关系“equ_config”不存在 - nested exception is org.postgresql.util.PSQLException: ERROR: relation "equ_config" does not exist org.postgresql.util.PSQLException:错误:关系“table_name”不存在 - org.postgresql.util.PSQLException:ERROR: relation "table_name" does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM