0

我试图执行一个非常基本的查询并且我收到 org.hibernate.QueryException: could not resolve property。这是我的实体:

@Entity

@Table(name = "pm_screenconfiguration") 公共类 ScreenConfiguration 扩展 PubliMovilEntity {

/**
 * serial.
 */
private static final long serialVersionUID = -5337034940299810600L;

@Id
@Column(name = "code")
private String code;

@Id
@Column(name = "companyCode")
private int companyCode;

@Id
@Column(name = "applicationId")
private int applicationId;


@Column(name = "value")
private String value;


/**
 * @return the code
 */
public String getCode() {
    return code;
}

/**
 * @param code the code to set
 */
public void setCode(String code) {
    this.code = code;
}

/**
 * @return the value
 */
public String getValue() {
    return value;
}

/**
 * @param value the value to set
 */
public void setValue(String value) {
    this.value = value;
}

/**
 * @return the companyCode
 */
public int getCompanyCode() {
    return companyCode;
}

/**
 * @param companyCode the companyCode to set
 */
public void setCompanyCode(int companyCode) {
    this.companyCode = companyCode;
}

/**
 * @return the applicationId
 */
public int getApplicationId() {
    return applicationId;
}

/**
 * @param applicationId the applicationId to set
 */
public void setApplicationId(int applicationId) {
    this.applicationId = applicationId;
}

}

这是我的查询:

public List<BaseEntity> getList(BaseSearchCriteria searchCriteria) {
    Criteria criteria = getSessionFactory() .openSession().createCriteria(ScreenConfiguration.class);
    if (searchCriteria.getApplicationId() != null) {
        criteria.add(Restrictions.eq("applicationId", searchCriteria.getApplicationId()));
    }

    if (searchCriteria.getCompanyCode() != null) {
        criteria.add(Restrictions.eq("companyCode", searchCriteria.getCompanyCode()));
    }

    return criteria.list();
}

我实在想不通。我使用 MySql 并且所有列都具有相同的实体名称。

谢谢。

4

1 回答 1

1

问题在于@Id 字段声明。当一个主键由多个字段组成时,您必须指定一个 IdClass。(还有另一种使用 @Embbeded 注释的方法)。

我创建了一个 IdClass,其中包含我用 @Id 注释的字段,并且在实体中我有该 IdClass 的引用。

@Entity
@Table(name = "pm_screenconf")
@IdClass(ScreenConfigurationPK.class)
public class ScreenConfiguration extends PubliMovilEntity {

请参阅:http ://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/ - 谢谢。

于 2013-02-10T23:22:11.877 回答