关系"hibernate_sequence"不存在

Environment:hibernate 4.1.8,postgresql 2

//问题描述:sql.SQLException: ERROR: relation "hibernate_sequence" does not exist.

原先的表结构:

CREATE TABLE tb_cat (   id   SERIAL,   name TEXT  );


---解决方法:

在表中创建sequence:

CREATE SEQUENCE hibernate_sequence;

CREATE TABLE tb_cat (  
  id   integer NOT NULL DEFAULT nextval('hibernate_sequence'), 
  name text);

再在类相应的hbm.xml文件中配置hibernate_sequence就行了:

<class name="Cat" table="tb_cat">
    <id name="id" column="id">
      <generator class="sequence">   
        <param name="sequence">hibernate_sequence</param>   
      </generator>
    </id>
    ...
</class>

P.S.:

postgresql好像不支持 <generator class="native" />.

你可能感兴趣的:(PostgreSQL,exist,not,does)