【发布时间】:2014-11-10 04:16:23
【问题描述】:
我需要将 JpaRepository 与包含联合语句的查询一起使用。可能吗?这是我目前的实现和我到目前为止得到的错误:
实体:
@Entity
public class PaymentDetails {
@Id
@Column
private String id;
@Enumerated(EnumType.STRING)
@Column(name = "rowtype")
private PaymentType paymentType;
@Embedded
private CardDetails cardDetails;
@Embedded
private BankAccountDetails bankAccountDetails;
接口和查询:
public interface PaymentsRepositoryManagerPayment1 extends JpaRepository<PaymentDetails,String> {
@Query(value = "select id,'CARD' as rowtype, cardnumber, cardtype, nameoncard, expirydate, startdate, securitycode, semafonecr, issuenumber, "
+ "null accountnumber, null accountholdername, null sortcode, null bic, null iban, null currency from pcs.BsbTempCardDetails "
+ "where id = :id union all select id, 'BANK' as rowtype, null cardnumber, null cardtype, null nameoncard, null expirydate, null startdate, "
+ "null securitycode, null semafonecr, null issuenumber, accountnumber, accountholdername, sortcode, bic, iban, currency "
+ "from pcs.BsbTempBankAccountDetails where id = :id", nativeQuery = true) <br>
List< PaymentDetails > findPaymentDetails(@Param("id") String id);
呼叫:
@Autowired private PaymentsRepositoryManagerPayment1 paymentsRepositoryManagerPayment1;
@Transactional(value = "paymentsRepositoryTransactionManager")
public PaymentDetails retrievePaymentDetailsById1(String id) {
return paymentsRepositoryManagerPayment1.findOne(id);
}
错误:
org.springframework.dao.InvalidDataAccessResourceUsageException:无法加载实体:[com.bskyb.repository.payments.model.PaymentDetails#cardId]; SQL [选择 paymentdet0_.id 作为 id2_0_,paymentdet0_.accountholdername 作为 accounth2_2_0_,paymentdet0_.accountnumber 作为 accountn3_2_0_,paymentdet0_.bic 作为 bic2_0_,paymentdet0_.currency 作为 currency2_0_,paymentdet0_.iban 作为 iban2_0_,paymentdet0_.sortcode 作为 sortcode2_0_,paymentdet0_.cardnumber 作为 cardnumber , paymentdet0_.cardtype as cardtype2_0_, paymentdet0_.expirydate as expirydate2_0_, paymentdet0_.issuenumber as issuenu11_2_0_, paymentdet0_.nameoncard as nameoncard2_0_, paymentdet0_.securitycode as securit13_2_0_, paymentdet0_.startdate as startdate2_0_, paymentdet0_.rowtype as rowtype2_0_ ?];嵌套异常是 org.hibernate.exception.SQLGrammarException:无法加载实体:[com.bskyb.repository.payments.model.PaymentDetails#cardId] java.sql.SQLSyntaxErrorException: ORA-00942: 表或视图不存在
【问题讨论】: