Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TABLE-generated IDs available on PrePersist #133

Closed
lukasj opened this issue Aug 9, 2016 · 8 comments · Fixed by #488
Closed

Make TABLE-generated IDs available on PrePersist #133

lukasj opened this issue Aug 9, 2016 · 8 comments · Fixed by #488

Comments

@lukasj
Copy link
Contributor

lukasj commented Aug 9, 2016

JSR-338/3.5.3 states that

Generated primary key values are available in the PostPersist method.

It'll be much helpful if those ids whose strategy is GenerationType.TABLE are available on PrePersist.

exempli gratia

public class MyEntity {

    @PrePersist
    private void onPrePersist() {
        // generate a unique and unchangable value from *available* id.
        derived = String.format("%1$016x", id);
    }

    @GeneratedValue(..., strategy = GenerationType.TABLE)
    @Id
    private Long id;

    @Basic(optional = false)
    @Colum(..., nullable = false, updatable = false)
    @NotNull
    private String derived;
}

Note that the derived column is not null and not updatable.

@lukasj
Copy link
Contributor Author

lukasj commented Aug 9, 2016

@glassfishrobot Commented
Reported by jinahya

@lukasj
Copy link
Contributor Author

lukasj commented Aug 22, 2016

@glassfishrobot Commented
neilstockton said:
FWIW DataNucleus JPA already does set ids from all non-IDENTITY value generators (i.e TABLE, SEQUENCE, custom) prior to PrePersist, so hence the values are available in that method.

@lukasj
Copy link
Contributor Author

lukasj commented May 5, 2017

@glassfishrobot Commented
This issue was imported from java.net JIRA JPA_SPEC-133

@lukasj
Copy link
Contributor Author

lukasj commented Aug 31, 2018

@gavinking
Copy link
Contributor

This is a pretty reasonable and useful request, it seems to me, and to be honest I'm not sure why Hibernate didn't already do things this way (I guess nobody ever asked us directly). But anyway, looks like I've been able to get that working with a very straightforward change. So from our side I don't think we would have a problem adding it to the spec.

@lukasj WDYT? What does EclipseLink do here?

@gavinking
Copy link
Contributor

I have proposed #488. Let's see if other implementors object.

@lukasj
Copy link
Contributor Author

lukasj commented Aug 24, 2023

EclipseLink already supports this

@gavinking
Copy link
Contributor

OK, so I checked with the Hibernate team and they do not object to the change.

@lukasj lukasj added this to To do in 3.2.0 via automation Aug 24, 2023
3.2.0 automation moved this from To do to Done Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3.2.0
Done
Development

Successfully merging a pull request may close this issue.

2 participants