开发者

Postgresql/openJPA (geronimo) Sequence Issue

开发者 https://www.devze.com 2023-03-05 00:44 出处:网络
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

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.

0

精彩评论

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