Skip to content

Non reactive method call error when running a native query #2873

@DavideD

Description

@DavideD

It happens when the method shouldFlush returns true in NativeQueryImpl#preapareForExecution:

	@Override
	protected void prepareForExecution() {
		final var spaces = getSynchronizedQuerySpaces();
		if ( spaces == null || spaces.isEmpty() ) {
			// We need to flush. The query itself is not required to execute in a
			// transaction; if there is no transaction, the flush would throw a
			// TransactionRequiredException which would potentially break existing
			// apps, so we only do the flush if a transaction is in progress.
			if ( shouldFlush() ) {
				getSession().flush();
			}
			// Reset the callback before every execution
			callback = null;
		}
		// Otherwise, the application specified query spaces via the Hibernate
		// SynchronizeableQuery and so the query will already perform a partial
		// flush according to the defined query spaces - no need for a full flush.
	}

Testcase:

	@Test
	public void shouldBeAbleToRunQueryWithMutinyTransactionAndFlush(VertxTestContext context) {
		test( context, getMutinySessionFactory()
				.withTransaction( s -> {
					s.setFlushMode( FlushMode.ALWAYS );
					return s
							.createNativeQuery( "select 42", Long.class ).getSingleResult()
							.call( s::flush );
				} ).invoke( result -> assertThat( result ).isEqualTo( 42L ) )
		);
	}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions