ObjectDB ObjectDB

Change Sequcene Id


could I change sequcence id ?

allocating small value may not be effect.

or something other ways ?

javax.jdo.datastore.Sequence seq = em.unwrap(javax.jdo.PersistenceManager.class).getSequence("MyEntity$identity");
long currentValue = seq.currentValue();
// I would like to change currentValue (because it is too big value)
seq.allocate(smallValue); // allocating to small value is not effect

MyEntity is defined with JPA

public class MyEntity {
    private Long id;



You cannot set the next id of an existing sequence. The purpose of the allocate(...) method is different (hint to improve efficiency by pre-allocating ids).

But you may define a new sequence with a new initial id, and set the relevant entity class to use the new sequence (note that you must verify that id collision is avoided and every entity object gets its own unique id).

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)


To post on this website please sign in.