This is my HibernateDaoImpl which is for get valuse from Emp and Org tables such as ORG_ID,ORG_NAME,ID,ORG_ID,EMP_ID,EMP_NAME,CARD_NUM,
ORG_PAY,EMP_PAY.
How I can use java code to iterator them to check this valuses which is or is not what I want to get ?
public List<Emp> findByOrgId(String orgId) throws Exception {
SessionFactory sf = HibernateSessionFactory.getSessionFactory();
Session session = sf.openSession();
String hql = "select o.orgId,o.orgName,e.empId,e.empName,e.cardNum,e.orgPay,e.empPay from Org o,Emp e where e.orgId=o.orgId and o.orgId=?";
Query query = session.createQuery(hql);
query.setString(0,orgId);
List list = query.list();
return list;
Your query expects a parameter (a value for
o.orgId), but you don’t pass any.The code should look like
Looking at the query, it alwo looks like the Emp entity should have an association to an Org entity rather than to have its ID. I would also name the entities Employee and Organization. Your code would be much more readable than with these 3-letters names.