Java 休眠中的本地生成器类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16373015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
native generator class in hibernate
提问by Rimchik
I have this part of hibernate mapping xml file, and I was looking for a good example for what does native mean.
我有 hibernate 映射 xml 文件的这一部分,我正在寻找一个很好的例子来说明本机的含义。
<hibernate-mapping>
<class name="com.hib.Task" table="tasks">
<id name="id" type="int" column="id" >
<generator class="native"/>
</id>
I know it's something related to unique identifier property, but I would really like to have an example.
我知道这与唯一标识符属性有关,但我真的很想举个例子。
Sorry for the newbie question, I'm new to hibernate and programming in general :) Thank you!
对不起,新手问题,我是休眠和编程的新手:) 谢谢!
采纳答案by Suresh Atta
Native means Your generator will use identity or sequence columns according to what your current database support.
本机意味着您的生成器将根据您当前数据库支持的内容使用标识或序列列。
Docs explained about each strategy here
文档在这里解释了每个策略
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id
native
本国的
selects identity, sequence or hilo depending upon the capabilities of the underlying database.
根据底层数据库的功能选择身份、序列或 hilo。
assigned
分配
lets the application assign an identifier to the object before save() is called. This is the default strategyif no element is specified.
让应用程序在调用 save() 之前为对象分配一个标识符。如果未指定元素,则这是默认策略。
For example: In Mysql if you have primary key column as a auto_increment, the db will be updated using this strategy
例如:在 Mysql 中,如果您将主键列作为 auto_increment,将使用此策略更新数据库
回答by Thomas de Verdière
And to complete what Suresh Atta said, you can name the sequence:
为了完成 Suresh Atta 所说的,您可以命名序列:
<hibernate-mapping>
<class name="com.hib.Task" table="tasks">
<id name="id" type="int" column="id" >
<generator class="native">
<param name="sequence">s_tasks</param>
</generator>
</id>
So it will either work for IDENTITY and for SEQUENCE incremented primary key.
因此,它既适用于 IDENTITY,也适用于 SEQUENCE 递增的主键。