HHH-18216 delegate @Save to insert() when entity has no id assigned

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-06-02 08:05:37 +02:00
parent 1657a19baf
commit 386bb1138a
1 changed files with 18 additions and 0 deletions

View File

@ -131,6 +131,24 @@ public class LifecycleMethod extends AbstractAnnotatedMethod {
.append(parameterName)
.append(") {\n\t");
}
if ( "upsert".equals(operationName) ) {
//TODO: only do this for @GeneratedValue
declaration
.append("\t\tif (")
.append(sessionName)
.append(".getFactory().getPersistenceUnitUtil().getIdentifier(")
.append(iterateParameter ? "_entity" : parameterName)
.append(") == null)\n")
.append("\t\t\t")
.append(sessionName)
.append('.')
.append("insert")
.append('(')
.append(iterateParameter ? "_entity" : parameterName)
.append(')')
.append(";\n")
.append("\t\telse\n\t");
}
declaration
.append("\t\t")
.append(sessionName)