Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取Hibernate:使用Hibernate将数据插入Postgres时,选择nextval(';Hibernate_序列';)错误_Hibernate_Postgresql - Fatal编程技术网

获取Hibernate:使用Hibernate将数据插入Postgres时,选择nextval(';Hibernate_序列';)错误

获取Hibernate:使用Hibernate将数据插入Postgres时,选择nextval(';Hibernate_序列';)错误,hibernate,postgresql,Hibernate,Postgresql,我刚开始冬眠。我使用Postgres作为我的数据库。我创建了一个简单的book类,并尝试将数据存储到名为book 这是我的图书课: package com.techno.domain; public class Book { private int id; private String name; private String authur; private String year_published; private String genere

我刚开始冬眠。我使用Postgres作为我的数据库。我创建了一个简单的book类,并尝试将数据存储到名为
book

这是我的图书课:

    package com.techno.domain;

public class Book {
    private int id;
    private String name;
    private String authur;
    private String year_published;
    private String genere;
    private int no_of_piece;

    /**
     * Default Constructor
     */
    public Book() {
        super();
    }

    /**
     * @param name
     * @param authur
     * @param year_published
     * @param genere
     * @param no_of_piece
     */
    public Book(String name, String authur, String year_published, String genere, int no_of_piece) {
        super();
        this.name = name;
        this.authur = authur;
        this.year_published = year_published;
        this.genere = genere;
        this.no_of_piece = no_of_piece;
    }

    /**
     * @param id
     * @param name
     * @param authur
     * @param year_published
     * @param genere
     * @param no_of_piece
     */
    public Book(int id, String name, String authur, String year_published, String genere, int no_of_piece) {
        super();
        this.id = id;
        this.name = name;
        this.authur = authur;
        this.year_published = year_published;
        this.genere = genere;
        this.no_of_piece = no_of_piece;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the authur
     */
    public String getAuthur() {
        return authur;
    }

    /**
     * @param authur
     *            the authur to set
     */
    public void setAuthur(String authur) {
        this.authur = authur;
    }

    /**
     * @return the year_published
     */
    public String getYear_published() {
        return year_published;
    }

    /**
     * @param year_published
     *            the year_published to set
     */
    public void setYear_published(String year_published) {
        this.year_published = year_published;
    }

    /**
     * @return the genere
     */
    public String getGenere() {
        return genere;
    }

    /**
     * @param genere
     *            the genere to set
     */
    public void setGenere(String genere) {
        this.genere = genere;
    }

    /**
     * @return the no_of_piece
     */
    public int getNo_of_piece() {
        return no_of_piece;
    }

    /**
     * @param no_of_piece
     *            the no_of_piece to set
     */
    public void setNo_of_piece(int no_of_piece) {
        this.no_of_piece = no_of_piece;
    }
}
我的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>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/library</property>
        <property name="connection.username">test</property>
        <property name="connection.password">password</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- <property name="hibernate.hbm2ddl.auto">validate</property> -->
        <!-- Use XML-based mapping metadata -->
        <mapping resource="com/techno/domain/Book.hbm.xml"/>

        <!-- Use Annotation-based mapping metadata -->
        <!-- <mapping class="com.techno.entity.Book" /> -->


    </session-factory>
</hibernate-configuration>
试试这个:

<id name="id" type="int" column="id">
      <generator class="sequence">book_id_seq
           <param name="sequence">book_id_seq</param>
      </generator>
</id>

图书编号
图书编号
试试这个:

<id name="id" type="int" column="id">
      <generator class="sequence">book_id_seq
           <param name="sequence">book_id_seq</param>
      </generator>
</id>

图书编号
图书编号
<id name="id" type="int" column="id">
      <generator class="sequence">book_id_seq
           <param name="sequence">book_id_seq</param>
      </generator>
</id>