users@jpa-spec.java.net

[jpa-spec users] Re: Possibly make the TABLE-generated IDs available on @PrePersist?

From: Oliver Gierke <ogierke_at_pivotal.io>
Date: Tue, 16 Aug 2016 12:47:46 +0200

Hi Jin,

I might be missing something obvious here but @PrePersist effectively implies *before* any database interaction. So how can the database generated be available at this time already?

Cheers,
Ollie

> Am 09.08.2016 um 11:26 schrieb Jin Kwon <jinahya_at_gmail.com>:
>
> JSR338/3.5.3 specified that
>
> Generated primary key values are available in the PostPersist method.
>
> Is it possibly to specify TABLE-generated IDs available on PrePersist?
>
> e.g.
> public class MyEntity {
>
> @PrePersist
> private void onPrePersist() {
> // make derived as a unique value derived from the id
> derived = String.format("%016x", id);
> }
>
> @GeneratedValue(..., strategy = GenerationType.TABLE)
> @Id
> private Long id;
>
> @Column(..., nullable = false, updatable = false)
> private String derived;
> }