休眠生成器增量与表自动增量冲突 [英] hibernate generator increment conflict with table auto increment

查看:115
本文介绍了休眠生成器增量与表自动增量冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在hbm文件中将生成器设置为'increment',并且还将auto_increment事物放入数据库表中。
这个证件显示问题....



这两件事是相冲突的吗? ?

解决方案

是的,它们是冲突的,没有意义。



当使用hibernate内置生成器'增量'时,通过从启动时的最大主键值开始计数来生成标识符是休眠的,在多JVM中不安全并使用数据库AUTO_INCREMENT,它是为新行生成唯一标识的数据库。



在mySQL DB中,如果使用AUTO_INCREMENT,则应该在映射中使用identity来让数据库安全地生成唯一标识。



来自hibernate文档

增量
$ b


当没有其他进程将数据插入到同一个表中时,生成只有
唯一的long,short或int类型的标识符。
不能在集群中使用。


身份 $ b


支持DB2,MySQL,MS SQL Server,Sybase和
HypersonicSQL中的标识列。返回的标识符类型为long,short或int。

更多信息

Hibernate Doc部分5.1.4.1。发电机

我的sql AUTO_INCREMENT文档


I set generator as 'increment' in hbm file, and also i put auto_increment thing in database table also. This creteria showing issue ....

This both thing is conflicting ? ?

解决方案

Yes they are conflicting, makes no sense..

When using hibernate built-in generator 'increment', it's hibernate that generate the identifiers by counting from the maximum primary key value at startup, not safe in multi JVM and using the database AUTO_INCREMENT it's the database that generate a unique identity for new rows.

In mySQL DB, if using AUTO_INCREMENT you should use identity in your mapping to let the database safely generate unique identity.

From hibernate documentation

increment

Generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.

identity

supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.

More information
Hibernate Doc section 5.1.4.1. Generator
My sql AUTO_INCREMENT documentation

这篇关于休眠生成器增量与表自动增量冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆