The exact time point when auto-assigned identity value of a persistent entity
is assigned is rather ill-defined in JPA spec. OpenJPA will assign this
identifier when the new entity is flushed/committed or when explicitly
requested via SPI-specific API.
For example, both of the following assertions should pass for entity with an
auto-assigned identifier
em.persist(pc);
em.flush();
assertNotNull(pc.getId());
or
em.persist(pc);
assertNotNull(OpenJPAPersistence.cast(em).getObjectId(pc));
ill-defined
Marcel Ruff wrote:
>
> Hi,
>
> having
>
> class Test
> @Id()
> @Column(name = "id", unique = true)
> @GeneratedValue(strategy = GenerationType.AUTO)
> public Long getId() {
> return this.id;
> }
>
> em.persist(test);
> test.getId() -----> IS NULL
>
> Shouldn't it contain the generated id filled by persist?
>
> Thanks
> Marcel
>
>
> --
> Marcel Ruff
> http://www.xmlBlaster.org
> http://watchee.net
> Phone: +49 7551 309371
>
>
>
--
View this message in context:
http://n2.nabble.com/Why-is-%40Id-GenerationType.AUTO-null-after-persist--tp678343p678701.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.