序列生成器在persistence.xml中

编程入门 行业动态 更新时间:2024-10-22 11:03:21
本文介绍了序列生成器在persistence.xml中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在JPA中,通常我们在实体bean中指定序列生成器。我们可以在persistence.xml中指定这个吗?如果是,请分享步骤neeeded

解决方案

您必须在orm.xml中指定它。在persistence.xml中使用这个元素:

< mapping-file> META-INF / orm.xml< / mapping-文件>

然后在您的orm.xml文件中(如果您在其中指定了不同的属性,orm.xml将覆盖注释)

<序列生成器名称=MY_SEQ分配大小=1序列-name =MY_SEQ initial-value =1/> < entity class =my.entities.Entityname =Entity> < table name =Entity/> <属性> < id name =id> < generated-value strategy =SEQUENCEgenerator =MY_SEQ/> < / id> < / attributes> < / entity>

在这种情况下,id属性将从orm.xml中设置。您正在使用的其他任何注释仍然有效。

In JPA, generally we specify the sequence generator in the entity bean. Can we specify this in the persistence.xml? if yes, pls share the steps neeeded

解决方案

You have to specify it in the orm.xml. In the persistence.xml use this element:

<mapping-file>META-INF/orm.xml</mapping-file>

Then in your orm.xml (orm.xml will override annotations if you specify different attributes in it)

<sequence-generator name="MY_SEQ" allocation-size="1" sequence-name="MY_SEQ" initial-value="1" /> <entity class="my.entities.Entity" name="Entity"> <table name="Entity"/> <attributes> <id name="id"> <generated-value strategy="SEQUENCE" generator="MY_SEQ"/> </id> </attributes> </entity>

In this case, the id property will be set from the orm.xml. Any other annotations you are using for other properties will still work.

更多推荐

序列生成器在persistence.xml中

本文发布于:2023-10-25 14:05:19,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生成器   序列   xml   persistence

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!