Skip to content

@Table Class supports Record (or AllArgsConstructor), but does not support @Transient. #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seminchoi opened this issue Mar 16, 2025 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@seminchoi
Copy link

seminchoi commented Mar 16, 2025

When using Persistable with a record class in an R2DBC Data Repository, I found that the record does not work properly with the @Transient annotation.

Here is a sample code:

@Table("sample")
@Builder
public record SampleRecord(
        @Id
        UUID id,

        @Transient
        boolean isNew
) implements Persistable<UUID> {
    @Override
    public UUID getId() {
        return id;
    }

    @Override
    public boolean isNew() {
        return isNew;
    }
}

public interface SampleRecordRepository extends R2dbcRepository<SampleRecord, UUID> {
}

And the test code:

@SpringBootTest
class Simpler2dbcPersistableExampleApplicationTests {
    @Autowired
    SampleRecordRepository sampleRecordRepository;

    @Test
    void recordTest() {
        UUID sampleId = UUID.randomUUID();

        SampleRecord sample = SampleRecord.builder()
                .id(sampleId)
                .isNew(true)
                .build();

        sampleRecordRepository.save(sample)
                .then(sampleRecordRepository.findById(sampleId))
                .block();
    }
}

Running this test produces the following error:

Required property name not found for class com.sem.simpler2dbcpersistableexample.Sample2
java.lang.IllegalStateException: Required property name not found for class com.sem.simpler2dbcpersistableexample.Sample2
	at org.springframework.data.mapping.PersistentEntity.getRequiredPersistentProperty(PersistentEntity.java:190)
	at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor$1.getParameterValue(InstantiationAwarePropertyAccessor.java:115)
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.extractInvocationArguments(ClassGeneratingEntityInstantiator.java:301)
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:273)
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:98)
	at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:106)
	at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.potentiallySetId(MappingR2dbcConverter.java:471)
	at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.lambda$populateIdIfNecessary$2(MappingR2dbcConverter.java:451)

After debugging the issue, I found that when creating the entity without using the default constructor, no additional actions are performed, such as injecting null values or default values, into fields annotated with @transient.

The same issue occurs with a class that only has an @AllArgsConstructor.

The issue can be reproduced at https://github.com/seminchoi/r2dbc-transient-issue

So, I was wondering if this behavior is intentional or if there are any plans to support it.

Additionally, I would like to know if I can contribute to fixing this issue. If so, could you guide me on which parts of the code I should modify?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 16, 2025
@seminchoi
Copy link
Author

seminchoi commented Mar 16, 2025

I mistakenly created the issue in the wrong repository and have posted the same issue in the spring-data-commons repository. (spring-projects/spring-data-commons#3256) So, I would like this issue to be closed.

@mp911de mp911de closed this as completed Mar 17, 2025
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants