3
在JPA中,通常我們在實體bean中指定序列生成器。我們可以在persistence.xml中指定這個嗎?如果是,請分享需要的步驟persistence.xml中的序列生成器
在JPA中,通常我們在實體bean中指定序列生成器。我們可以在persistence.xml中指定這個嗎?如果是,請分享需要的步驟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>
在這種情況下,ID屬性將從orm.xml中設置。您正在爲其他屬性使用的任何其他註釋仍然有效。
謝謝你的工作 –