我正在使用JPA和Hibernate来执行简单的查询。它是从两个表,一个应用程序表和一个Transaction表中提取的连接。我可以看到数据返回,但它无法填充我创建的这个POJO,并且无法进行转换。这是查询:
public interface TransactionRepository extends JpaRepository<Transaction, String>{
@Query(value="SELECT "
+ " TXN.TAX_ID taxId, "
+ " APP.AP_DT apDt, "
+ " TXN.TXN_ID txnId"
+ " FROM "
+ " APPLICATION APP "
+ " JOIN "
+ " TRANSACTION TXN "
+ " ON "
+ " TXN.TXN_ID = APP.TXN_ID "
+ " WHERE"
+ " APP.CONFIRMATION_ID = ?1", nativeQuery=true)
AnnuityNetPdfToFims getInfoForPdfToFims(String confirmationId);
这是交易实体
@Entity
@Table(name="\"TRANSACTION\"")
@NamedQuery(name="Transaction.findAll", query="SELECT t FROM Transaction t")
public class Transaction implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="TXN_ID")
private String txnId;
@Column(name="ACCT_NUM")
private String acctNum;
@Column(name="ACCT_TYPE_CODE")
private String acctTypeCode;
@Column(name="AGENT_ID")
private String agentId;
@Column(name="AUTO_SUITABILITY_IND")
private String autoSuitabilityInd;
@Column(name="CARRIER_ID")
private String carrierId;
@Column(name="CHANNEL_NAME")
private String channelName;
@Column(name="COMPANY_NAME")
private String companyName;
@Column(name="DELIVERY_STATE")
private String deliveryState;
@Column(name="FIMS_DOCUMENT_ID")
private String fimsDocumentId;
@Column(name="INTERNAL_CONVERSION_IND")
private String internalConversionInd;
@Column(name="JOINT_OWNER_STATE")
private String jointOwnerState;
@Column(name="OWNER_FIRST_NAME")
private String ownerFirstName;
@Column(name="OWNER_LAST_NAME")
private String ownerLastName;
@Column(name="OWNER_TYPE_CODE")
private String ownerTypeCode;
@Column(name="PERSON_IND")
private String personInd;
@Column(name="PRODUCT_CODE")
private String productCode;
@Column(name="PRODUCT_CUSIP")
private String productCusip;
@Column(name="RESIDENCE_STATE")
private String residenceState;
@Column(name="REVIEWER_ID")
private String reviewerId;
@Column(name="SOLICITATION_STATE")
private String solicitationState;
@Column(name="STATUS_CODE")
private String statusCode;
@Column(name="STEP_ACTION_CODE")
private String stepActionCode;
@Column(name="STEP_NAME")
private String stepName;
@Column(name="TAX_ID")
private String taxId;
@Column(name="TR_BY_ID")
private String trById;
@Column(name="TR_TS")
private Timestamp trTs;
@Column(name="TXN_QUALIFIED_IND")
private String txnQualifiedInd;
@Column(name="TXN_XML")
private String txnXml;
@Column(name="UNIT_ID")
private String unitId;
@Column(name="VENDOR_APP_ID")
private String vendorAppId;
@Column(name="G_NUM")
private String gNum;
@Column(name="XTRAC_WORKITEM_ID")
private String xtracWorkitemId;
public Transaction() {
}
//getters and setters
这是应用程序实体
@Entity
@NamedQuery(name="Application.findAll", query="SELECT a FROM Application a")
public class Application implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ApplicationPK id;
@Temporal(TemporalType.DATE)
@Column(name="AP_DT")
private Date apDt;
@Column(name="DTCC_APPSUB_XML")
private String dtccAppsubXml;
@Column(name="PROCESSING_CODE")
private String processingCode;
@Column(name="TXN_ID")
private String txnId;
public Application() {
}
//getters and seters
这是我想要填充查询的POJO。
public class AnnuityNetPdfToFims
{
private String confirmationId;
private String taxId;
private Date apDt;
private long fimsReturnNum;
private String txnId;
//getters and setters
所以我可以看到数据又回来了,但它会以Object []的形式返回。我想我可以用它来填充POJO,但我不认为这是非常可靠的。我听说有一种方法可以使用@SqlResultSetMapping注释,但还没有成功使用它。我也听说过我可以在查询中指定对象的实际名称,如下所示:How to map a native query to POJO class using jpa and hibernate。
然而,我也无法让它发挥作用。有什么建议?提前致谢。