Postgresql/openJPA (geronimo) 序列问题
我在序列方面遇到了一个奇怪的问题。我使用 postgresql 9 和 geronimo 2.2。我已经在数据库环境中创建了序列 PLANTS_ID_SEQ
,当我尝试创建新实体时,我在日志中收到错误(来自 postegresql),关系 PLANTS_ID_SEQ
存在。它似乎试图创建已经创建的序列。这是来自实体 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;
请注意,如果我更改序列名称(例如sequenceName="MY_SEQ"
),那么代码会正确运行,但它会在 postgresql 中创建(并且显然使用)MY_SEQ顺序。如果有人对此案有任何线索,请分享。 谢谢乔治
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你的表有一个 SERIAL 类型的列,那么 postgres 将为你创建序列并在插入时自动使用它。
它创建的序列被命名为“tablename_id_seq”...
可能您正在尝试复制 postgres 已经完成的操作,并创建一个重复的序列。
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.
已解决:
应在 persistence.xml 中添加以下属性:
这样,openjpa 的 MappingTool 就不会尝试再次创建序列。
Solved:
Should add in persistence.xml the following property:
this way, the MappingTool of openjpa will not try to create the sequence again.