خرید بک لینک

Vote count: 0

I know this kind of question has been asked thousands of times already, but I think I have a different problem. So, I have a class A, which has a collection of objects of class B and a getter for this collection:

public class A {
     private String Id;
     private ArrayList<B> bees;
     public ArrayList<B> getBees(){
        ArrayList<Criterion> criterions = new ArrayList<>();
        criterions.add(Restrictions.eq("Id", this.Id));        
        retu (ArrayList<B>)DatabaseHelper.getObjectByCriteria(criterions, B.class);
     }
}

And DatabaseHelper.getObjectByCriteria code:

public static List getObjectByCriteria(ArrayList<Criterion> cr, Class classType){        
        List result = new ArrayList();        
        Session session = MyHibeateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(classType);        
        if (cr != null){
            for (Criterion criterion : cr){
            criteria.add(criterion);
            }        
        }
        result = criteria.list();
        if (session.isOpen()){
            session.close();
        }         
        retu result;

    }

When I run this query (select * from table_b where id = 123) in MySQLWorkbench I get two different rows with different values. However, the "result" list retued by DatabaseHelper.getObjectByCriteria contains two indentical objects with identical ids and values.

I don't use any kind of hibeate aotations

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 15 فروردين 1395 ساعت: 21:52

صفحه بندی