PROBLEM: I am having a problem regarding the database under the server in SQL Server which has Server Property > Connection > NOCOUNT ON (is ticked). The table has no trigger, absolutely nothing FYI.
What I am trying to do it just to do a simple insert using
repository.save(entity)
or entityManager.persist(entity)
but I got an error:
Unexpected row count: -1; expected: 1.
I cannot get an entity out and edit it also => there will be an error
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
I have tried to make a custom Dialect to insert a SET NOCOUNT OFF
before every query but it didn't work.
The custom dialect:
package com.ata2.art22;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.type.StandardBasicTypes;
public class CustomSQLServerDialect extends SQLServer2012Dialect {
public CustomSQLServerDialect() {
super();
registerFunction("concat", new StandardSQLFunction("concat", StandardBasicTypes.STRING));
}
@Override
public String getSequenceNextValString(String sequenceName) {
return "SET NOCOUNT OFF;\n" + super.getSequenceNextValString(sequenceName);
}
}
The property file setting:
spring.jpa.properties.hibernate.dialect=com.ata2.art22.CustomSQLServerDialect
QUESTION: Is there any other ways or changes I need to do to be able to use methods from repository or entityManager WITHOUT turning off the NOCOUNT ON at the Database Server configuration or using native query?