0

I am trying to make a hibernate call. I have a scenario in which I will fetch data and I will update the table.(no insert and delete functionality). The table does not have any primary key or foreign key relationships.

code:

 @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;
}

}

Service layer:

@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

public class MrpsDepositDAOImpl extends AbstractDaoImpl implements 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;
}

}

public abstract class AbstractDaoImpl implements 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();
}

}

Problem: Whenever I make a call, it returns empty list, though the data is there in the deposit_id table in mysql database.

Question: 1. How should I have to make a hibernate call if it is a non-entity class. 2. Should mapping is required in hibernate.cfg.xml even though it MRPSDeposit is a non-entity class.

Right now the hibernate.cfg.xml have the mapping value for MRPSDeposit table.

<mapping class="com.**.**.**.MRPSDeposit" />
bharathi
  • 6,019
  • 23
  • 90
  • 152
  • Is there a good reason why you want to use a non-entity class as if it is an entity class? Why not make it an entity class (add an `@Entity` annotation)? – Jesper Sep 20 '16 at 13:32
  • Its a existing table in production. I just need to pull the data from the existing table. @Entity need a primary key. where as the table which I am trying to access does not have primary key column itself – bharathi Sep 20 '16 at 13:36
  • In that case, see for example: [JPA entity without id](http://stackoverflow.com/questions/3820897/jpa-entity-without-id) and [JPA entity has no primary key?](http://stackoverflow.com/questions/21397393/jpa-entity-has-no-primary-key). You'll need a trick like the answers in those questions show if the table has no primary key. – Jesper Sep 20 '16 at 13:40
  • Any idea how can I resolve with for no primary key table. Any possibility to make a call to no primary key table in MySQL database? – bharathi Sep 20 '16 at 13:44
  • Look at the answers in the two questions that I linked above. – Jesper Sep 20 '16 at 13:45

0 Answers0