I have the following Entity:
@Entity
@Table(name = "signing_keys")
@Getter
@Setter
public class SigningKeysEnt {
@Id
private Long id;
@Column(name = "encrypted_private_key")
private String encryptedPrivateKey;
@Column(name = "public_key")
private String publicKey;
@Column(name = "protocol_version")
private String protocolVersion;
@Column(name = "signature_algorithm")
private String signatureAlgorithm;
@Column(name = "expiration_date")
private Date expirationDate;
}
JPA Repository:
@Repository
public interface SigningKeysRepository extends JpaRepository<SigningKeysEnt, Long> {
@Query(value = """
SELECT public_key AS publicKey,
protocol_version AS protocolVersion,
expiration_date AS expirationDate
FROM signing_keys
""", nativeQuery = true)
List<SigningKey> getPublicKeys();
}
DAO which I need to return:
public class SigningKey {
private String publicKey;
private String protocolVersion;
private Date expirationDate;
// getter/setter
}
I need to return List<SigningKey>
but I get: Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.SigningKey]
I tried to use Class-Based Projections
by adding constructor into SigningKey DAO like this:
public class SigningKey {
private String publicKey;
private String protocolVersion;
private Date expirationDate;
public SigningKey() {
}
public SigningKey(String publicKey, String protocolVersion, Date expirationDate) {
this.publicKey = publicKey;
this.protocolVersion = protocolVersion;
this.expirationDate = expirationDate;
}
/// getter/setter
}
But still I get the same error.
Are there other ways to fix the issue? I need to use Class-Based Projections in order to avoid code refactoring.
6
Can it be not native query?
Something like:
@Query(value = "SELECT new your.package.SigningKey(sk.publicKey, sk.protocolVersion, sk.expirationDate " +
"FROM signing_keys sk")
List<SigningKey> getPublicKeys();