spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
3.03k stars 1.42k forks source link

Use Class, Enum, Constants, ... inside @Query anontation #3651

Closed nhaphanse closed 2 weeks ago

nhaphanse commented 1 month ago

Dear Team,

I hope this message finds you well.

I wanted to bring up a concern regarding the use of DTO projects, particularly when it comes to utilizing constants in @Query annotations without specifying their full relative paths. For example, I currently have the following query:

@Query("select new com.food.customer.CustomerModel(c.id, c.name) " +
       "from Customer c where c.id = com.food.customer.CustomerModel.ORIGINAL")
List<CustomerModel> findCustomerModel();

While the integrator can assist to some extent, the long and often duplicated paths can be quite inconvenient in our projects.

Could you please provide support in finding a more efficient solution for this situation? Your assistance would greatly enhance our workflow.

Thank you for your help!

David

mp911de commented 1 month ago

We're exploring DTO rewriting with #3076. Our query rewriting is intentionally limited. We do not want to parse queries in order to build another model of the query. For using constants: You can always use parametrized queries and pass in the external value.

Hibernate calls out that enum literals do not require qualifiers.

Any non-entity-related constants must be fully-qualified.

That being said, it seems that there's nothing actionable left in the ticket.

spring-projects-issues commented 3 weeks ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 2 weeks ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.