Deniz
Deniz

Reputation: 137

adding object to list overwrite some results

I added objects to list however there was overriding problem.How can solve this? I sended 3 value in transactionIdList in my main method. these three value to send below method, i want to add all results return. However there is only two results return with bsList which are in the ( basvuru != null && !basvuru.isEmpty())) state.

     List<ApplicationResult> bsList = new ArrayList();
     Application bsDB = new Application();

     for (int i = 0; i < transactionIdList.size(); i++) {
        List basvuru = session.createQuery("from Application as bsvr where bsvr.transactionId = :var1").setParameter("var1", transactionIdList.get(i)).list();
        if (basvuru == null) {
           ApplicationResult bss = new ApplicationResult();
           bss.setTransactionId(transactionIdList.get(i));
           bss.setBasvuruDurum("no value");
           bsList.add(bss);
        } else if (basvuru != null && !basvuru.isEmpty()){
           ApplicationResult bs = new ApplicationResult();
           bsDB = (Application) basvuru.get(0);
           bs.setTransactionId(bsDB.getTransactionId());
           bs.setBasvuruDurum(bsDB.getDurum());
           bsList.add(bs); 
        }
    }

Upvotes: 0

Views: 65

Answers (3)

Trying
Trying

Reputation: 14278

in List implementation values never get overridden. You must have some other issue. could be basvuru is not null

Upvotes: 0

Nick
Nick

Reputation: 1822

It is most likely that basvruru at some time is not null but an empty list. In this case, nothing is added to the bsList.

You probably want to update the if clause to basvuru == null || basvuru.isEmpty(), and just use and else.

Upvotes: 1

Crazyjavahacking
Crazyjavahacking

Reputation: 9687

The only explanation is that session.createQuery() returns one List that is not null, but is empty.

Upvotes: 2

Related Questions