I am trying to use Spring JPA's projection to filter out unnecessary data from query result. However, I have multiple projections that will need to be used on the same interface method.
The problem is, I am trying to query data from the same method with a different returning object but java doesn't allowed this.
The query are auto generated by JPA based on method name, so I cannot make changes to method name.
Is there a alternative, other than creating a new interface, since I think it's a hassle and unnecessary
here is a sample code, of what I am trying to do.
Auto-Generated Query
public interface UserRepository extends CrudRepository<UserAccount, Long> {
AuthenticateProjection getByUsername(String username);
UserDetailsProjection getByUsername(String username);
}
Projections
public interface AuthenticateProjection {
@Value("#{target.username}")
String getUsername();
@Value("#{target.credentail.token}")
String getHashPassword();
}
public interface UserDetailsProjection {
@Value("#{target.username}")
String getUsername();
@Value("#{target.firstname}")
String getFirstName();
@Value("#{target.lastname}")
String getLastName();
}