带有AttributeOverride的hibernate加载记录返回NoSuchFieldException

时间:2015-05-01 14:34:57

标签: java hibernate nosuchfileexception

由于我有三个具有相似结构的数据库表,我创建了一个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

如果有人能解释我的错误,我真的很感激... 谢谢!

0 个答案:

没有答案