2011-08-11 13 views

回答

8

您必須在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中設置。您正在爲其他屬性使用的任何其他註釋仍然有效。

+0

謝謝你的工作 –