Hibernate调用不适用于非实体类

时间:2016-09-20 13:21:59

标签: java hibernate

我正在尝试进行休眠调用。我有一个场景,我将获取数据,我将更新表。(没有插入和删除功能)。 该表没有任何主键或外键关系。

代码:

 @Table(name = "deposit_id")
  public class MRPSDeposit {

private Date DPST_DTE;

private short DPST_NUM;
private char EXPAND_IND; // CHAR(1) NOT NULL,
private char PRCS_CDE; // CHAR(1) NOT NULL,
private char DPST_ID_TYP; // CHAR(1) NOT NULL,
private char DPST_ID_DATA; // CHAR(20) NOT NULL,
private char PMT_STS; // CHAR(2) NOT NULL,
private Date PMT_STS_DTE; // DATE NOT NULL,
private Number DPST_ID_AMT; // DECIMAL(11, 2) NOT NULL,
private char OP_ID; // CHAR(4) NOT NULL,
private char OP_SITE_ID; // CHAR(2) NOT NULL,
private char OP_UNT_ID; // CHAR(2) NOT NULL,
private char DPST_CHK_NUM; // CHAR(11) NOT NULL

public Date getDPST_DTE() {
    return DPST_DTE;
}

public void setDPST_DTE(Date dPST_DTE) {
    DPST_DTE = dPST_DTE;
}

public short getDPST_NUM() {
    return DPST_NUM;
}

public void setDPST_NUM(short dPST_NUM) {
    DPST_NUM = dPST_NUM;
}



public char getEXPAND_IND() {
    return EXPAND_IND;
}

public void setEXPAND_IND(char eXPAND_IND) {
    EXPAND_IND = eXPAND_IND;
}

public char getPRCS_CDE() {
    return PRCS_CDE;
}

public void setPRCS_CDE(char pRCS_CDE) {
    PRCS_CDE = pRCS_CDE;
}

public char getDPST_ID_TYP() {
    return DPST_ID_TYP;
}

public void setDPST_ID_TYP(char dPST_ID_TYP) {
    DPST_ID_TYP = dPST_ID_TYP;
}

public char getDPST_ID_DATA() {
    return DPST_ID_DATA;
}

public void setDPST_ID_DATA(char dPST_ID_DATA) {
    DPST_ID_DATA = dPST_ID_DATA;
}

public char getPMT_STS() {
    return PMT_STS;
}

public void setPMT_STS(char pMT_STS) {
    PMT_STS = pMT_STS;
}

public Date getPMT_STS_DTE() {
    return PMT_STS_DTE;
}

public void setPMT_STS_DTE(Date pMT_STS_DTE) {
    PMT_STS_DTE = pMT_STS_DTE;
}

public Number getDPST_ID_AMT() {
    return DPST_ID_AMT;
}

public void setDPST_ID_AMT(Number dPST_ID_AMT) {
    DPST_ID_AMT = dPST_ID_AMT;
}

public char getOP_ID() {
    return OP_ID;
}

public void setOP_ID(char oP_ID) {
    OP_ID = oP_ID;
}

public char getOP_SITE_ID() {
    return OP_SITE_ID;
}

public void setOP_SITE_ID(char oP_SITE_ID) {
    OP_SITE_ID = oP_SITE_ID;
}

public char getOP_UNT_ID() {
    return OP_UNT_ID;
}

public void setOP_UNT_ID(char oP_UNT_ID) {
    OP_UNT_ID = oP_UNT_ID;
}

public char getDPST_CHK_NUM() {
    return DPST_CHK_NUM;
}

public void setDPST_CHK_NUM(char dPST_CHK_NUM) {
    DPST_CHK_NUM = dPST_CHK_NUM;
}

}

服务层:

@Override
@Transactional(readOnly = true)
public List<MRPSDeposit> getDepositDetails(String searchCondition,
        String searchText) throws InfoManagementException {
    List<MRPSDeposit> mrpsDepositDetails = new ArrayList<MRPSDeposit>();
    /* try { */

    mrpsDepositDetails = mrpsDepositDao.findBySearchCondition(
            searchCondition, searchText);

    return mrpsDepositDetails;

}


 @Repository

公共类MrpsDepositDAOImpl扩展AbstractDaoImpl实现了MrpsDepositDao {

@Autowired
private SessionFactory sessionFactory;

protected MrpsDepositDAOImpl() {
    super(MRPSDeposit.class);
}


@Override
public List<MRPSDeposit> findBySearchCondition(String searchCondition,
        String searchText) {
    List<MRPSDeposit> searchResult = super.findByCondition(searchCondition,
            searchText);
    System.out.println(searchText+"searchText"+searchCondition+"syso"+searchResult);
    return searchResult;
}

}

公共抽象类AbstractDaoImpl实现         AbstractDao {

private Class<E> entityClass;

@Autowired
private SessionFactory sessionFactory;

protected AbstractDaoImpl(Class<E> entityClass) {
    this.entityClass = entityClass;
}

  @SuppressWarnings("unchecked")
@Override
public List<E> findByCondition(String searchCondition, String searchText) {
    // TODO Auto-generated method stub
    System.out.println("sezrc"+ searchCondition+ "---searchtext"+searchText);
    Criteria criteria = getCurrentSession().createCriteria(entityClass);
    criteria.add(Restrictions.eq(searchCondition, searchText));
    return criteria.list();
}

}

问题:  每当我打电话时,它都会返回空列表,尽管数据存在于mysql数据库的deposit_id表中。

问题: 1.如果它是非实体类,我应该如何进行休眠调用。 2.即使MRPSDeposit是非实体类,也应该在hibernate.cfg.xml中进行映射。

现在,hibernate.cfg.xml具有MRPSDeposit表的映射值。

<mapping class="com.**.**.**.MRPSDeposit" />

0 个答案:

没有答案