If you want an object with name you can use someth...
# spring
x
If you want an object with name you can use something like
Copy code
@Query("select new com.packageName.SomeDTO(field, field, field, name) from ...")
Actually, this probably won't work with nativequery.
n
lol, I'm so confused. if let's say you would to do this? Is there easier way? How would you do it?
x
haha, yeah sorry. I spouted some nonsense first and then work took over and I forgot the whole thing. Watch this space...
👍 1
You have at least 3 options to achieve that now. Adding a direct dependency to the users entity and using JPAQL to map that directly to the DTO with @Query and
new com.packge...
constuctor call. You can also use nativequery to with the @Query annotation but to map it into an object automatically it needs to be a namedquery with a resultsetmapping defined for it (like in here: https://stackoverflow.com/questions/29082749/spring-data-jpa-map-the-result-to-non-entity-pojo#answer-31966870). The third one is to drop outside of the interface and implement it manually with
RowMapper
. I'd go with number 1 first if there is nothing preventing you adding that dep (like attempts to a bounded context), if that's not possible I'd go with number 3.
n
Thank you sir, much appreciated I will explore and let you know.