Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ public class StaleStateException extends HibernateException {
public StaleStateException(String message) {
super( message );
}

/**
* Constructs a {@code StaleStateException} using the supplied message
* and cause.
*
* @param message The message explaining the exception condition
* @param cause An exception to wrap
*/
public StaleStateException(String message, Exception cause) {
super( message, cause );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.jdbc.Expectation;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.sql.model.ast.ColumnValueBinding;
Expand Down Expand Up @@ -46,6 +47,10 @@ public MergeOperation createMergeOperation(OptionalTableUpdate optionalTableUpda
optionalTableUpdate.getMutatingTable().getTableMapping(),
optionalTableUpdate.getMutationTarget(),
getSql(),
// Without value bindings, the upsert may have an update count of 0
optionalTableUpdate.getValueBindings().isEmpty()
? new Expectation.OptionalRowCount()
: new Expectation.RowCount(),
getParameterBinders()
);
}
Expand Down Expand Up @@ -228,16 +233,18 @@ protected void renderMergeUpdate(OptionalTableUpdate optionalTableUpdate) {
final List<ColumnValueBinding> valueBindings = optionalTableUpdate.getValueBindings();
final List<ColumnValueBinding> optimisticLockBindings = optionalTableUpdate.getOptimisticLockBindings();

renderWhenMatched( optimisticLockBindings );
appendSql( " then update set " );
for ( int i = 0; i < valueBindings.size(); i++ ) {
final ColumnValueBinding binding = valueBindings.get( i );
if ( i > 0 ) {
appendSql( ", " );
if ( !valueBindings.isEmpty() ) {
renderWhenMatched( optimisticLockBindings );
appendSql( " then update set " );
for ( int i = 0; i < valueBindings.size(); i++ ) {
final ColumnValueBinding binding = valueBindings.get( i );
if ( i > 0 ) {
appendSql( ", " );
}
binding.getColumnReference().appendColumnForWrite( this, null );
appendSql( "=" );
binding.getColumnReference().appendColumnForWrite( this, "s" );
}
binding.getColumnReference().appendColumnForWrite( this, null );
appendSql( "=" );
binding.getColumnReference().appendColumnForWrite( this, "s" );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jdbc.Expectation;
import org.hibernate.persister.entity.mutation.EntityTableMapping;
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.tree.Statement;
Expand Down Expand Up @@ -39,6 +40,10 @@ public MutationOperation createMergeOperation(OptionalTableUpdate optionalTableU
optionalTableUpdate.getMutatingTable().getTableMapping(),
optionalTableUpdate.getMutationTarget(),
getSql(),
// Without value bindings, the upsert may have an update count of 0
optionalTableUpdate.getValueBindings().isEmpty()
? new Expectation.OptionalRowCount()
: new Expectation.RowCount(),
getParameterBinders()
);

Expand Down Expand Up @@ -193,17 +198,19 @@ protected void renderMergeUpdate(OptionalTableUpdate optionalTableUpdate) {
final List<ColumnValueBinding> valueBindings = optionalTableUpdate.getValueBindings();
final List<ColumnValueBinding> optimisticLockBindings = optionalTableUpdate.getOptimisticLockBindings();

appendSql( " when matched then update set " );
for ( int i = 0; i < valueBindings.size(); i++ ) {
final ColumnValueBinding binding = valueBindings.get( i );
if ( i > 0 ) {
appendSql( ", " );
if ( !valueBindings.isEmpty() ) {
appendSql( " when matched then update set " );
for ( int i = 0; i < valueBindings.size(); i++ ) {
final ColumnValueBinding binding = valueBindings.get( i );
if ( i > 0 ) {
appendSql( ", " );
}
binding.getColumnReference().appendColumnForWrite( this, "t" );
appendSql( "=" );
binding.getColumnReference().appendColumnForWrite( this, "s" );
}
binding.getColumnReference().appendColumnForWrite( this, "t" );
appendSql( "=" );
binding.getColumnReference().appendColumnForWrite( this, "s" );
renderMatchedWhere( optimisticLockBindings );
}
renderMatchedWhere( optimisticLockBindings );
}

private void renderMatchedWhere(List<ColumnValueBinding> optimisticLockBindings) {
Expand Down
Loading
Loading