Saturday, July 17, 2010

JPA and primary key sequence generation

Nothing is easy...

I do:
create sequence GEO_MESSAGES_LOG_SEQ;

and I assign the primary key as "sequence generated".
This entails these annotations:

@SequenceGenerator(name="GEO_MESSAGES_LOG_ID_GENERATOR", sequenceName="GEO_MESSAGES_LOG_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="GEO_MESSAGES_LOG_ID_GENERATOR")

I immediately get this error:

Exception [TOPLINK-7027]

Exception Description: The sequence named [GEO_MESSAGES_LOG_SEQ] is setup incorrectly. Its increment does not match its pre-allocation size.

in @SequenceGenerator I add allocationSize=1

and things magically work... I suspect performance will not be great...

No comments: