在JPA中,通常我们在实体bean中指定序列生成器。我们可以在 persistence.xml 中指定这一点吗?如果是,请分享所需的步骤
您必须在 orm.xml 中指定它。在 persistence.xml 中使用此元素:
<mapping-file>META-INF/orm.xml</mapping-file>
然后在你的orm.xml中(如果你在其中指定不同的属性,orm.xml将覆盖注释)
<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>
在这种情况下,将从 orm.xml 设置 id 属性。您用于其他属性的任何其他注释仍然有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)