Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Re: Why is @Id GenerationType.AUTO null after persist?

Pinaki Poddar

2008-08-07

Replies: Find Java Web Hosting

Author LoginPost Reply

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

--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.