October 24, 2024
Chicago 12, Melborne City, USA
java

Access param from a Object in a native query


I need to access Object param like the below code into native query. I don’t want to pass 10 params as a method arguments.

@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;
}

Repository:

public interface AuthorRepository extends JpaRepository<SigningKeysEnt, Long> {
 
    @Query(value = "SELECT * FROM author WHERE key = :obj.publicKey", nativeQuery = true)
    List<SigningKeysEnt> findByFirstName(@Param("obj") SigningKeysEnt obj);
}

But above solution is not working in native queries. Is there something close to above way which can be used to pass Java object and access object values into the native SQL query?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video