I created a method which through spring data automatically create the query. The problem is about the return param, because dismatch from the name definition. In fact by specifying only one parameter, it return 4 parameters.
The springData method is that:
Optional<Comunicazioni> getCommIDByExtIDAndCommSAndCommT(
BigDecimal extID, String commS, String commT);
and I access to the type like so:
getCommIDByExtIDAndCommSAndCommT(extId, commS, commT).get().getCommID()
how can I retrieve only the column I need?
Thank you
Unfortunately, this is not possible with the current implementation of Spring Data JPA (i.e. Using method name only).
Instead, the current solution is to use @Query to define the return values. You can find an example of that here.
However, if your Entity object is not too large, you would be able to achieve the result in the example you posted by simply retrieving the entire entity:
Optional<Comunicazioni> findByExtIDAndCommSAndCommT(BigDecimal extID, String commS, String commT);
and then calling it as
repo.findByExtIDAndCommSAndCommT(extId, commS, commT).get().getCommID();
It would be nice to see this functionality in the future, but for now, it is not so difficult to work around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With