查询MySql视图时出现SQLGrammar错误

时间:2018-09-18 09:38:07

标签: mysql hibernate spring-boot view

运行GET请求时,我得到一个异常 ohengine.jdbc.spi.SqlExceptionHelper:即使我已配置了堆栈跟踪,在堆栈跟踪中“字段列表”中的未知列“ disburseme0_.reason_type” 实体类中正确输入字段。我有一个Spring Boot SOAP接口,用于查询MySql数据库视图。我已经从父表中分配了唯一键之一作为JPA中的视图ID。

我的实体类的一部分具有:

@Entity
@Table(name="disbursement_payload")

public class Disbursement {
@Id 
@Column(name="ID")
private long disbursementId;

@Column(name="ReasonType")  
private String reasonType;
public long getDisbursementId() {
    return disbursementId;
}
public void setDisbursementId(long disbursementId) {
    this.disbursementId = disbursementId;
public String getReasonType() {
    return reasonType;
}
public void setReasonType(String reasonType) {
    this.reasonType = reasonType;
}

我的看法是:

CREATE VIEW disbursement_payload AS (
  SELECT 
   iso_number AS Currency,
trans_desc AS ReasonType,
account_number AS ReceiverParty,
amount AS Amount
  FROM m_payment_detail, m_loan_transaction 
  WHERE m_payment_detail.`id`= m_loan_transaction.`payment_detail_id` AND 
m_payment_detail.`payment_type_id`=2
); 

实体或视图定义中是否缺少某些内容?我在这里could not extract ResultSet in hibernate阅读了其中之一,我可能必须明确定义父模式。任何帮助,深表感谢。

1 个答案:

答案 0 :(得分:0)

根据基于驼峰式转换的db列和类var名称的映射,该转换基于下划线_分隔的名称

您可以尝试使用

    CREATE VIEW disbursement_payload AS (
      SELECT iso_number AS currency
      , trans_desc AS reason_type
      , account_number AS receiver_rarty
      , amount AS amount
      FROM m_payment_detail
      INNER JOIN m_loan_transaction 
          ON  m_payment_detail.`id`= m_loan_transaction.`payment_detail_id` 
            AND m_payment_detail.`payment_type_id`=2
    ); 

视图代码是SQL代码,并且休眠将视图视为表,因此列名的转换基于相同的规则

和一个建议,您不应该根据应在何处使用(较新的)explicic sin sintax来使用条件(较旧)。