Hibernate自动增量属性

发布于 2024-09-29 16:39:58 字数 313 浏览 0 评论 0原文

我知道你可以通过映射自动增加一个id;

<id column="user_id" name="id" >
<generator class="increment"/>
</id>

但是是否也可以增加一个属性,到目前为止我所尝试的方法都不起作用;

<property column="numeric_value" name="nr" >
<generator class="increment"/>
</property>

I know you can auto-increment an id by mapping;

<id column="user_id" name="id" >
<generator class="increment"/>
</id>

But is it also possible increment a property, what I tried so far didn't work;

<property column="numeric_value" name="nr" >
<generator class="increment"/>
</property>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-10-06 16:39:58

但是是否也可以增加一个属性,到目前为止我所尝试的方法都不起作用;

不,你不能在 中使用 (或者,用简单的英语编写,Hibernate 仅支持使用生成器作为标识符特性)。

也许看看 生成 属性 如果您可以依赖数据库来生成值(例如使用触发器)。

参考文献

But is it also possible increment a property, what I tried so far didn't work;

No, you can't use a <generator> inside a <property> (or, to write it in plain english, Hibernate only supports using a generator for identifier properties).

Maybe have a look at generated properties if you can rely on the database to generate the value (e.g. using a trigger).

References

陌生 2024-10-06 16:39:58

这取决于数据库以及您创建表的方式。例如,如果您使用Mysql,那么表中的id字段应该为该字段设置自动增量。 Hibernate 不会生成它,而是依赖数据库来完成它。如果您使用 Hibernate 工具来生成表,它会适当地生成表。您可以参考http:// /docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-id

It would depend on database and how you have created the table. For example if you are using Mysql, then in the table id field should have auto increment set for the field. Hibernate will not generate it, but rather depend on database to do it. If you use Hibernate tools to generate tables, it would take care of generating tables appropriately. You can refer to http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-id

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文