Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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_Jakarta Ee_Jsf 2_Generator - Fatal编程技术网

Hibernate 休眠生成类

Hibernate 休眠生成类,hibernate,jakarta-ee,jsf-2,generator,Hibernate,Jakarta Ee,Jsf 2,Generator,我正在使用hibernate应用程序将数据存储在我从POJO创建的HBM文件中的Postgres数据库中。该表由ID组成,ID为bigserial,应自动生成。但当我在插入记录后运行project时,它不会增加id的值,因此引发异常: SEVERE: ERROR: duplicate key value violates unique constraint "usertable_pkey" SEVERE: Could not synchronize database state with s

我正在使用hibernate应用程序将数据存储在我从POJO创建的HBM文件中的Postgres数据库中。该表由ID组成,ID为
bigserial
,应自动生成。但当我在插入记录后运行project时,它不会增加id的值,因此引发异常:

 SEVERE: ERROR: duplicate key value violates unique constraint "usertable_pkey"
 SEVERE: Could not synchronize database state with session
 org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
我的HBM条目如下:

<id name="userid" type="long">
        <column name="userid" />
        <generator class="assigned" />
    </id>


有人能建议我使用哪个生成器类来解决此问题吗?

插入事务数据时,最好使用
[sequence][2]
来生成对象的id

<id ....>
        <generator class="sequence">
           <param name="sequence">YOUR_SEQUENCE _NAME</param>
       </generator>
</id>

您的\u序列\u名称
这将确保即使在多线程环境中,您也可以为不同的对象获得不同的id

阅读有关生成器类的API