简体   繁体   English

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

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

I am trying to learn hibernate framework with making a simple program that push a class Cliente into a table on postgres, The error that returns is as follow: 我正在尝试通过制作一个简单的程序来学习休眠框架,该程序将类Cliente推入postgres的表中,返回的错误如下:

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Caused by: org.postgresql.util.PSQLException: ERROR: the relation "clienti_id_seq" does not exist

This is my database by PGAdmin (sorry for imgur i can't upload picture directly) http://i.imgur.com/Fz9o1fR.png?1 这是PGAdmin的数据库(对不起imgur,我无法直接上传图片) http://i.imgur.com/Fz9o1fR.png?1

This is the class Cliente 这是类Cliente

public class Cliente {

private long clienteId;
private String clienteNome;
private String clienteCognome;
private String clienteTelefono;
private String clienteMail;
private String clientePermesso;
private long clienteCommessa;

public long getClienteId() {
    return clienteId;
}

public void setClienteId(long clienteId) {
    this.clienteId = clienteId;
}

public String getClienteNome() {
    return clienteNome;
}

public void setClienteNome(String clienteNome) {
    this.clienteNome = clienteNome;
}
public String getClienteCognome() {
    return clienteCognome;
}

public void setClienteCognome(String clienteCognome) {
    this.clienteCognome = clienteCognome;
}

 public String getClienteTelefono() {
    return clienteTelefono;
}

public void setClienteTelefono(String clienteTelefono) {
    this.clienteTelefono = clienteTelefono;
}

 public String getClienteMail() {
    return clienteMail;
}

public void setClienteMail(String clienteMail) {
    this.clienteMail = clienteMail;
}

 public String getClientePermesso() {
    return clientePermesso;
}

public void setClientePermesso(String clientePermesso) {
    this.clientePermesso = clientePermesso;
}

 public long getClienteCommessa() {
    return clienteCommessa;
}

public void setClienteCommessa(long clienteNome) {
    this.clienteCommessa = clienteCommessa;
}

}

This is my mapping file 这是我的映射文件

<hibernate-mapping>
<class name="beans.Cliente" table="Clienti">
    <id name="clienteId" type="integer" column="id" >

        <generator class="sequence"> 
            <param name="sequence">CLIENTI_ID_seq</param>            
        </generator>
    </id>
    <property name="clienteNome" column="nome" type="string">            
    </property>
    <property name="clienteCognome" column="cognome" type="string">            
    </property>
        <property name="clienteTelefono" column="telefono" type="string">            
    </property>
    <property name="clienteMail" column="mail" type="string">            
 </property>
        <property name="clientePermesso" column="permesso" type="string">            
    </property>
    <property name="clienteCommessa" column="commessa" type="string">            
</property>
</class>
</hibernate-mapping>

This is the hibernate cfg.xml file, the information about url pass and user are correct 这是hibernate cfg.xml文件,有关url pass和user的信息正确

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration   DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql:postgres</property>

<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/Georilievi</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">Fabio1990</property>
<property name="hibernate.current_session_context_class">thread</property>


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

</hibernate-configuration>

This is the main file, here i create an istance of Cliente, and try to push in the postgres database 这是主文件,在这里我创建一个Cliente实例,然后尝试推送postgres数据库

package main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import beans.Cliente;

public class Main {
public static void main(String [] args){
    // Create a configuration instance
    Configuration configuration = new Configuration();
    // Provide configuration file
    configuration.configure("hibernate.cfg.xml");
    // Build a SessionFactory
    SessionFactory factory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().configure().build());
    // Get current session, current session is already associated with Thread
    Session session = factory.getCurrentSession();

    // Begin transaction

    session.getTransaction().begin();

    Cliente cliente = new Cliente();
    cliente.setClienteNome("Fabio");
    cliente.setClienteCognome("Tramontana");
    cliente.setClienteTelefono("3343052346");
    cliente.setClienteMail("info.tramontanafabio@gmail.com");
    cliente.setClientePermesso("admin");
    cliente.setClienteCommessa(0);
    // Save*/
    session.save(cliente);
    // Commit, calling of commit will cause save an instance of employee
    session.getTransaction().commit();
    }
}

thanks all of you for helping me, i don't understand the error, i think it is in the declaration of the generator. 谢谢大家帮助我,我不明白错误,我认为这是在发电机的声明中。

Please try changing the generator class from sequence to identity and see. 请尝试将生成器类从序列更改为标识并查看。 I guess the issue is the auto generation of IDs. 我想问题是自动生成ID。

See these links: http://www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-property 请参阅以下链接: http : //www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-property

暂无
暂无

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

相关问题 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 如何解决“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:错误:关系“用户”不存在 - SpringBoot,Hibernate,Postgresql - org.postgresql.util.PSQLException: ERROR: relation "users" does not exist - SpringBoot, Hibernate, Postgresql 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 org.postgresql.util.PSQLException:错误:关系“ employee1”不存在 - org.postgresql.util.PSQLException: ERROR: relation “employee1” does not exist 通过JDBC进行Postgres连接:org.postgresql.util.PSQLException:错误:关系“处方”不存在 - Postgres connectivity via JDBC: org.postgresql.util.PSQLException: ERROR: relation “prescriptions” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM