infobip / infobip-spring-data-querydsl

Infobip Spring Data Querydsl provides new functionality that enables the user to leverage the full power of Querydsl API on top of Spring Data repository infrastructure.
Apache License 2.0
278 stars 57 forks source link

two entity join but when projection is null? #91

Closed basquiat78 closed 1 year ago

basquiat78 commented 1 year ago

e.g

queryDsl.query {
            it.select(Projections.constructor(MyDto::class.java,
                customer.id,
                customer.name,
                customer.createdAt,
                customer.updatedAt,
                order.id.`as`("orderId"),
                // do other 
                order.createdAt.`as`("orderAt")
                order.updatedAt.`as`("orderUpdateAt")
                )
            )
            .from(customer)
            .innerJoin(order).on(customer.id.eq(order.customerId))
            .where(customer.id.eq(id))
        }

error

org.springframework.data.mapping.model.MappingInstantiationException:
blah, blah blah,  arguments 1, john doe, 2023-06-12T10:42:23,2023-06-14T13:42:01, null, null, null

I have given aliases to duplicate column names. However, when the variable names in the custom and order entities are the same, the subsequent columns appear as null.

of course, f there are no conflicting columns, the execution proceeds successfully.

What are the possible solutions I can consider to resolve this issue?

lpandzic commented 1 year ago

Honestly I don't use aliases, with records creating new projection types is really cheap.

lpandzic commented 1 year ago

Does this work with regular querydsl? I'm trying to understand whether this is a general querydsl problem or something specific to this project.

basquiat78 commented 1 year ago

@lpandzic

ok, I have identified the issue regarding this

i debug MappingR2dbcConverter -> readFrom

this issue is due to PascalNameStrategy

Both column names and aliases are affected by this PascalNameStrategy.

if use PascalNameStrategy, aliases columName change OrderAt

if use CamelNameStrategy, , aliases columName change order_at

but queryDSL with JPA, aliase columName is 'orderAt', not changed

so For this reason, failed mapping property

Therefore, depending on the strategy used, this aspect should also be handled accordingly.

# if use PascalNameStrategy
e.g  order.createdAt.`as`("OrderAt")

# if use CamelNameStrategy
e.g  order.createdAt.`as`("order_at")
lpandzic commented 1 year ago

Ok, so you sorted out your problem? Nothing should be changed in the project?

basquiat78 commented 1 year ago

@lpandzic

Yes! But you need to guideline this issue

lpandzic commented 1 year ago

Can you create a PR with the fix and a test?

lpandzic commented 1 year ago

I'm closing this one as stale.