Skip to content

Commit 386bb11

Browse files
committed
HHH-18216 delegate @save to insert() when entity has no id assigned
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 1657a19 commit 386bb11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/LifecycleMethod.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ private void delegateCall(StringBuilder declaration) {
131131
.append(parameterName)
132132
.append(") {\n\t");
133133
}
134+
if ( "upsert".equals(operationName) ) {
135+
//TODO: only do this for @GeneratedValue
136+
declaration
137+
.append("\t\tif (")
138+
.append(sessionName)
139+
.append(".getFactory().getPersistenceUnitUtil().getIdentifier(")
140+
.append(iterateParameter ? "_entity" : parameterName)
141+
.append(") == null)\n")
142+
.append("\t\t\t")
143+
.append(sessionName)
144+
.append('.')
145+
.append("insert")
146+
.append('(')
147+
.append(iterateParameter ? "_entity" : parameterName)
148+
.append(')')
149+
.append(";\n")
150+
.append("\t\telse\n\t");
151+
}
134152
declaration
135153
.append("\t\t")
136154
.append(sessionName)

0 commit comments

Comments
 (0)