openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From realdepp <>
Subject Issues with GeneratedValue and SequenceGenerator
Date Tue, 05 Apr 2011 22:36:08 GMT

I'm working with OpenJPA 2.1.0 and have (simplified) the following
superclass. All "real" entities derive from that class:

public abstract class MyBase {
    private long id;

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public final long getId() {
        return id;
    public final void setId(long id) { = id;

I'm persisting the classes with the following code:

    EntityTransaction et = em.getTransaction();
    // Huh!?
    System.out.println(myEntity.getId() + " == 0");

The System.out always sais "0 == 0", however in the database there is a
correct generated id.

Am I missing something?

Another thing:

The same scenario as above, but a different strategy for @GeneratedValue: 
    @SequenceGenerator(name = "My_Seq", initialValue = 100000,
allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =

The same error as above, but additionally, the "initialValue" is ignored,
the ID in the db starts with "1".
Did I trigger a bug or did I make a mistake?

Thanks a lot.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message