I am having a weird problem with a sequence. Im using postgresql 9 with geronimo 2.2. I have created the sequence PLANTS_ID_SEQ
inside the db environment and when I try to create a new entity I get an e开发者_JAVA技巧rror in my logs (which comes from postegresql) that the relation PLANTS_ID_SEQ
exists. It seems that it tries to create the sequence that is already created. This is the code from the entity bean:
@Id
@GeneratedValue(generator="PLANTS_SEQ",strategy=GenerationType.SEQUENCE) @SequenceGenerator(name="PLANTS_SEQ", sequenceName="PLANTS_ID_SEQ",allocationSize=1) @Column(name = "ID")
private Integer id;
Please notice that if I change the sequence name (eg sequenceName="MY_SEQ"
)then the code runs correctly but it creates in postgresql (and obviously uses) the MY_SEQ sequence. If anyone has a clue about this case please share.
Thanks George
If your table has a column of type SERIAL, then postgres will create the sequence for you and use it automatically on inserts.
The sequence it creates is named "tablename_id_seq"...
Probably you're trying to duplicate what postgres has already done, and create a duplicate sequence.
Solved: Should add in persistence.xml the following property:
property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(Sequences=false)"
this way, the MappingTool of openjpa will not try to create the sequence again.
精彩评论