1

由于我有三个具有相似结构的数据库表,因此我创建了一个 Embeddable 类以用作它们的 id:

@Embeddable
public class AcceptanceCriteriaId implements Serializable{

    private String requestValue;
    private String bpvValue;
    private Long customerId;

    @Column(name="requestValue")
    public String getRequestValue() {
        return requestValue;
    }

    public void setRequestValue(String requestValue) {
        this.requestValue = requestValue;
    }

    @Column(name="bpvValue")
    public String getBpvValue() {
        return bpvValue;
    }

    public void setBpvValue(String bpvValue) {
        this.bpvValue = bpvValue;
    }

    @Column(name="customerId")
    public Long getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }
}

然后,表的三个实体类会将列的名称覆盖为它们自己的名称:

@Entity
@Table(name = "RSK_XML_TYPE_AC_TBL")
public class TypeAcceptanceCriteria{

    private AcceptanceCriteriaId acceptanceCriteriaId;
    private ResponseValue response;

    @EmbeddedId
    @AttributeOverrides(
            {
                    @AttributeOverride(name = "requestValue", column = @Column(name = "REQUEST_TYPE")),
                    @AttributeOverride(name = "bpvValue", column = @Column(name = "bpv_type")),
                    @AttributeOverride(name = "customerId", column = @Column(name = "customer_uid"))
            }
    )
    public AcceptanceCriteriaId getAcceptanceCriteriaId() {
        return acceptanceCriteriaId;
    }

    public void setAcceptanceCriteriaId(AcceptanceCriteriaId acceptanceCriteriaId) {
        this.acceptanceCriteriaId = acceptanceCriteriaId;
    }

    @Column(name="response_uid")
    @Type(type="com.modules.avm.riskxmlservice.response.utils.ResponseValueEnumType")
    public ResponseValue getResponse() {
        return response;
    }

    public void setResponse(ResponseValue response) {
        this.response = response;
    }
}

所以,如果这里没有错误,我希望这两种方法中的一种可以工作:

@Repository
public class HibernateTypeAcceptanceCriteriaDAO extends AbstractAvmAppHibernateDAO<TypeAcceptanceCriteria> implements TypeAcceptanceCriteriaDAO {
    protected HibernateTypeAcceptanceCriteriaDAO() {
        super(TypeAcceptanceCriteria.class);
    }

    public TypeAcceptanceCriteria getTypeAcceptanceCriteria_v1(String requestValue, String bpvValue, Long customerId) {
        return (TypeAcceptanceCriteria) createCriteria()
                .add(Restrictions.eq("acceptanceCriteriaId.requestValue", requestValue))
                .add(Restrictions.eq("acceptanceCriteriaId.bpvValue", bpvValue))
                .add(Restrictions.in("acceptanceCriteriaId.customerId", new Long[]{0L, customerId}))
                .add(Restrictions.sqlRestriction(" ROWNUM = 1 "))
                .addOrder(Order.desc("acceptanceCriteriaId.customerId"))
                .uniqueResult();
    }

    @Override
    public TypeAcceptanceCriteria getTypeAcceptanceCriteria(String requestValue, String bpvValue, Long customerId) {
        return (TypeAcceptanceCriteria) getSession().createSQLQuery("select * from RSK_XML_type_AC_TBL where request_type = :requestValue and bpv_type= :bpvValue and customer_uid in (0, :customerId) and rownum = 1 order by customer_uid desc")
                .setResultTransformer(new AliasToBeanResultTransformer(TypeAcceptanceCriteria.class))
                .setString("requestValue", requestValue)
                .setString("bpvValue", bpvValue)
                .setLong("customerId", customerId).uniqueResult();
    }

}

但我收到以下错误:java.lang.RuntimeException: java.lang.NoSuchFieldException: REQUEST_TYPE

如果有人能解释我做错了什么,我将不胜感激......谢谢!

4

0 回答 0