简体   繁体   中英

Getting auto-generated value on insert with JPA 2

I am using JPA 2 to model some entities in my application. In some of the models, there are particular columns whose value is populated on insert. An example of such column would be:

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "timestamp", nullable = false, insertable = false, updatable = false)
private Calendar timestamp;

Now I would like that on save, the generated value of the column would be populated automatically so that it's available from the application code. With Hibernate, I can use the @Generated annotation, however I would like to keep ORM specific code out of my application and use native JPA only.

Is this possible with just native JPA?

Thanks in advance for your time.

如果您想在JPA中保持这种逻辑,我想生命周期侦听器可能会有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM