开发者

Sequence Generator in persistence.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜