openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Re: Issues with GeneratedValue and SequenceGenerator
Date Wed, 06 Apr 2011 14:45:06 GMT
I'm guessing that this might have to do with your enhancement method? If you
are using the eclipse plugin... that is most likely the problem. See
OPENJPA-1879[1] for details.

[1] https://issues.apache.org/jira/browse/OPENJPA-1879

Thanks,
Rick

On Tue, Apr 5, 2011 at 5:36 PM, realdepp <thepsycho@freenet.de> wrote:

> 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.
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message