Hinrik (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMmE4YWRkOTcz...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16692?atlOrigin=eyJpIjoiMmE4YW...
) HHH-16692 (
https://hibernate.atlassian.net/browse/HHH-16692?atlOrigin=eyJpIjoiMmE4YW...
) Hibernate 6.2 broke hybrid before/after execution ID generators (
https://hibernate.atlassian.net/browse/HHH-16692?atlOrigin=eyJpIjoiMmE4YW...
)
Issue Type: Bug Assignee: Unassigned Created: 25/May/2023 02:06 AM Priority: Major
Reporter: Hinrik (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
In Hibernate 6.2, it seems my ID generator can no longer work.
My generator uses an identity column/post-insert-id by default, but will use an explicitly
supplied ID if entity.getExplicitId() returns non-null. This is handy when data is in the
process of being migrated and the service can both insert new IDs as well as consume
inserts (using supplied IDs) from another source.
The problem is that in 6.2, the way to choose between generation before execution
(supplied ID) and generation after execution (post-insert) is via
org.hibernate.generator.Generator.generatedOnExecution(). This method does not take the
entity object as an argument, so the generator cannot decide at runtime which strategy to
use. Is there another way to do it?
For reference, here is my generator implementation which was working in previous Hibernate
versions:
public class ExplicitOrAutoGenerator extends IdentityGenerator {
@Override
public Serializable generate(SharedSessionContractImplementor s, Object obj) {
if (obj instanceof ExplicitId entity && entity.getExplicitId() != null) {
return entity.getExplicitId();
}
return IdentifierGeneratorHelper.POST_INSERT_INDICATOR;
}
}
If I use it as-is (by implementing the new IdentifierGenerator interface), an insert with
a post-insert ID just fails because it tries to call the entity ID setter with
POST_INSERT_INDICATOR (which is not a Long or Integer obviously).
(
https://hibernate.atlassian.net/browse/HHH-16692#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16692#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:0428b75 )