ObjectDB ObjectDB

Change Sequcene Id

#1

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


@Entity
public class MyEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
}

 

edit
delete
#2

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
edit
delete

Reply

To post on this website please sign in.