Skip to content

Add support for @Transactional in native images #28717

Closed
@mhalbritter

Description

@mhalbritter

When running the jdbc-tx sample in sb-3.0.x branch from spring-native, it fails with:

java.lang.IllegalStateException: Failed to execute CommandLineRunner
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:769) ~[jdbc-tx:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:750) ~[jdbc-tx:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[jdbc-tx:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[jdbc-tx:3.0.0-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[jdbc-tx:3.0.0-SNAPSHOT]
        at app.main.SampleApplication.main(SampleApplication.java:23) ~[jdbc-tx:0.0.1.BUILD-SNAPSHOT]
Caused by: java.lang.IllegalArgumentException: Expected transaction
        at org.springframework.util.Assert.isTrue(Assert.java:121) ~[na:na]
        at app.main.Runner.run(Runner.java:53) ~[jdbc-tx:0.0.1.BUILD-SNAPSHOT]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:766) ~[jdbc-tx:3.0.0-SNAPSHOT]
        ... 5 common frames omitted

This is the run method:

	@Override
	@Transactional
	public void run(String... args) throws Exception {
		Assert.isTrue(TransactionSynchronizationManager.isActualTransactionActive(), "Expected transaction");
		try {
			find(1L);
		}
		catch (EmptyResultDataAccessException e) {
			entities.update(ADD_FOO, 1L, "Hello");
		}
	}

I guess that @Transactional doesn't work in native-image.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)theme: aotAn issue related to Ahead-of-time processing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions