Skip to main content

Toplink ValidationException with DB Sequence (B42 03/26)

8 replies [Last post]
isana
Offline
Joined: 2005-11-10
Points: 0

Hello,

When I deployed my application to B42 (03/26) and launched my client application, the following exception was thrown.
----
Caused by: Exception [TOPLINK-7027] (Oracle TopLink Essentials - 2006.3 (Build 060324)): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: The sequence named [CHANNEL_SEQ] is setup incorrectly. Its increment does not match its pre-allocation size.
at oracle.toplink.essentials.exceptions.ValidationException.sequenceSetupIncorrectly(ValidationException.java:1278)
at oracle.toplink.essentials.sequencing.StandardSequence.createVector(StandardSequence.java:149)
at oracle.toplink.essentials.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:85)
at oracle.toplink.essentials.sequencing.Sequence.getGeneratedVector(Sequence.java:266)
at oracle.toplink.essentials.internal.sequencing.SequencingManager$Preallocation_NoTransaction_State.getNextValue(SequencingManager.java:532)
at oracle.toplink.essentials.internal.sequencing.SequencingManager.getNextValue(SequencingManager.java:830)
at oracle.toplink.essentials.internal.sequencing.ClientSessionSequencing.getNextValue(ClientSessionSequencing.java:95)
at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:225)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.assignSequenceNumber(UnitOfWorkImpl.java:323)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:3196)
at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:294)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3147)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:149)
... 29 more
----

CHANNEL_SEQ is the database sequence for my entity. I specify it as follows.
----
@Id
@SequenceGenerator(name = "CHANNEL_SEQ", allocationSize = 25)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CHANNEL_SEQ")
private Long id;
----

The database sequence object is created by Tolplink's schema generation feature. And it worked properly with B36. The generated DDL is as follows:
----
CREATE SEQUENCE CHANNEL_SEQ INCREMENT BY 25
----

My application has several entities with such @Id annotations. They also causes the exception above when they are being created.

Thank you.
- Ryosuke

Message was edited by: isana

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hlaebe
Offline
Joined: 2005-01-14
Points: 0

Hello,

the following setup works for me with Oracle XE

@Id
@SequenceGenerator(name = "PROPS_GEN", sequenceName = "PROPS_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PROPS_GEN")
@Column(name="PROP_ID")
private int mId;

guess it should work with others , too

isana
Offline
Joined: 2005-11-10
Points: 0

Hello,

Thank you very much. It worked with my @Entity objects on B44 :
- changed allocationSize value from 25 to 1.
- specified sequenceName.

Now I can avoid effort to create workaround codes! Thank you, again.

- Ryosuke.

gyorke
Offline
Joined: 2005-06-21
Points: 0

This is a known issue with support for changes the specification made with regards to 'initialValue' of the @SequenceGenerator. This 'initalValue' is being interpreted as being the first value returned by the database sequence, but this 'initialValue' should be interpreted to be the first value returned from the @SequenceGenerator and the provider should configure the Database sequence to achieve this. In the case of an Oracle database sequence the first value from the sequence ("starts with") should be inialized to be initialValue + pre-allocation size. This problem has been recorded in the GF bug base as issue number 689.
--Gordon

isana
Offline
Joined: 2005-11-10
Points: 0

Hello, Gordon.

Thank you for pointing the related issue. I added myself to the issue's CC.

- Ryosuke.

isana
Offline
Joined: 2005-11-10
Points: 0

Hello,

I noticed that the exception I reported is thrown when em.persist() is invoked for the first time for each persistent class. Next time of em.persist() succeeds.

I tested with B42 03/27, Windows XP, JDBC connected Oracle.

Best regards,
- Ryosuke.

isana
Offline
Joined: 2005-11-10
Points: 0

Hello, again.

When I removed 'allocationSize' from @SequenceGenerator annotation, the same exception was thrown.

Regards,
- Ryosuke.

defectus
Offline
Joined: 2006-01-12
Points: 0

I've encoutered the same behaviour before (http://forums.java.net/jive/message.jspa?messageID=91090&tstart=75) but I didn't find any solution neither work-around yet.

isana
Offline
Joined: 2005-11-10
Points: 0

Hello, defectus.

I'm very sorry for too late...

Today, I tried my application with B44 and I found that B44 still have this problem.

As I posted, this exception is thrown only once for each persistent entity. So, I'm expecting that calling EntityManager.persist() for every @Entity object in my app. can be a workaround. For example, suppose that my application has @Entity objects A, B, C. I'm planning to add a SessionBean which just does the following:
--
EntityManager em;
try{
em.persist(new A());
} catch (Exception e) {
// ignore exception
}
try {
em.persist(new B());
} catch (.....) {}
...
// Finally, throw an exception to cause transaction rollback.
throw new SomeException();
--
I don't want to do such a thing, but I have to avoid this problem anyway... If this succeeds, I will post so.

Thank you.
- Ryosuke.