Reputation: 1172
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
Upvotes: 4
Views: 8771
Reputation: 2939
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.
Upvotes: 9