0

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 error 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

4

2 回答 2

1

如果您的表有一个 SERIAL 类型的列,那么 postgres 将为您创建序列并在插入时自动使用它。

它创建的序列名为“tablename_id_seq”......

可能您正在尝试复制 postgres 已经完成的操作,并创建一个重复的序列。

于 2011-05-11T21:25:39.457 回答
0

已解决:应该在 persistence.xml 中添加以下属性:

property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(Sequences=false)" 

这样openjpa的MappingTool就不会再尝试创建序列了。

于 2011-05-15T13:35:07.923 回答