nonouco
nonouco

Reputation: 1170

Postgresql/openJPA (geronimo) Sequence Issue

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

Upvotes: 0

Views: 505

Answers (2)

nonouco
nonouco

Reputation: 1170

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.

Upvotes: 0

bobflux
bobflux

Reputation: 11591

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.

Upvotes: 1

Related Questions