Insert trigger results in "unexpected row count" error

I’m inserting into a view in sqlite that has an “instead of insert” trigger on it. It doesn’t return a count of the number of rows affected. When I try to perform an insert hibernate errors with this message:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; statement executed: insert into...
Is there a way to fix this on the hibernate side?

The easiest way to do this probably to write a custom MetadataContributor and call org.hibernate.mapping.PersistentClass#setCustomSQLInsert for the entity in question. There you pass null, false, ExecuteUpdateResultCheckStyle.NONE and this should be good to go.

1 Like

Works great. Thanks!

import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.NONE;

import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataContributor;
import org.jboss.jandex.IndexView;
import org.kohsuke.MetaInfServices;

public class HibernateMetadataContributor implements MetadataContributor {
  public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
        .setCustomSQLInsert(null, false, NONE);

This is what I used.