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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With