spring-projects / spring-data-r2dbc

Provide support to increase developer productivity in Java when using Reactive Relational Database Connectivity. Uses familiar Spring concepts such as a DatabaseClient for core API usage and lightweight repository style data access.
Apache License 2.0
708 stars 132 forks source link

Field/column names getting appended with a dash and 7 characters, causing entity mapping and query projection to fail #803

Closed grice-globality closed 1 year ago

grice-globality commented 1 year ago

This is for postgresql. I've got an Entity that looks like this:


@Table("entity_type")
data class EntityType(
    @Id var id: UUID? = null,
    val entityTypeName: Name, // A string value class
    val systemSchemaVersion: SchemaVersion, // another string value class
)

And a table that looks like this:


    CREATE TABLE IF NOT EXISTS entity_type (
    id                      uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
    entity_type_name                    character varying NOT NULL,
    system_schema_version   character varying NOT NULL,

and accompanying interface:

interface EntityTypeRepository : CrudRepository<EntityType, EntityTypeIdType> {
    fun <S: EntityType> save(entity: S): EntityType
    fun findByEntityTypeName(entityTypeName: Name): EntityType?

I get this:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property 'entityTypeName-9XaHgsA' found for type 'RuleType'
    at app//org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:91)
    at app//org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:438)
    at app//org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:414)
    at app//org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:367)
    at java.base@17.0.4/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330)
    at app//org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:349)
    at app//org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:332)
    at app//org.springframework.data.repository.query.parser.Part.<init>(Part.java:81)

Why on EARTH is it appending "9XaHgsA" to the field/column name? It does this across ALL columns except the ID column.

Note that i'm using value classes, but that doesn't seem to cause a problem - they're automatically getting translated to strings as expected.

Also, note that this process goes through with the normal names first - I've stepped through in debugger - but then starts appending the 7 digit suffix for some reason second go-around.

mp911de commented 1 year ago

Closing as duplicate of https://github.com/spring-projects/spring-data-commons/issues/2736.