Problems adding beans to BeanItemContainer

I have a problem where even though I am adding many different beans to my BeanItemContainer, the size of the container remains 1.

I am using the following code to populate BeanItemContainer with bean objects:

public BeanItemContainer<Incident> getAllIncidents() {
        BeanItemContainer<Incident> all = new BeanItemContainer<Incident>(Incident.class);
        DBCollection coll = mDb.getCollection("Accident");
        DBCursor cursor = coll.find();
        System.out.println("coll count: " + coll.count());
        try {
           while(cursor.hasNext()) {
               DBObject o =;   
               Incident i = convertJSONToBean(o.toString());
               System.out.println("id:" + i.get_id());
               System.out.println("count:" + all.size());
        } finally {
        return all;

The output is:

coll count: 1000

The beans are definitely different objects, so I am not sure why the count remains at 1. Can someone point out what I am doing wrong? Thank you.

What does Incident::equals() Incident::hashCode() methods look like ??

the BeanItemContainer uses the bean itself as the unique ItemID , so you should make sure equals() hashCode() is correctly defined.

Check the result of the addBean method it should return a BeanItem instance or null if it did not add the item…

Thank you for your help. My Incident class extended com.mongodb.BasicDBObject and I found that the BasicDBObject class does override equals and hashcode methods. The result of the addBean() method was null except for the first bean.

I changed to use the BeanContainer class and all is working now.