openjpa-users mailing list archives

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

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

@MappedSuperclass
public abstract class MyBase {
    private long id;

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

I'm persisting the classes with the following code:

    EntityTransaction et = em.getTransaction();
    et.begin();
    em.persist(myEntity);
    et.commit();
    // 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: 
    @Id
    @SequenceGenerator(name = "My_Seq", initialValue = 100000,
allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"My_Seq")

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: http://openjpa.208410.n2.nabble.com/Issues-with-GeneratedValue-and-SequenceGenerator-tp6244055p6244055.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message