androidsugarorm

Sugar orm just save one record


I'm new developer sugar orm,create this entity on that:

public class READINGTBL extends SugarRecord {
    @Unique
    public String geographicalCode, sCode,subscriberId,  fullName,lastReadingDate,lastReadingDigit,dailyConsumptionAverage,readingStatus,waterMeterStatus,readingType,familyPopulation,waterConsumptionDetail,propertyUsageDetail,splitDiameter,debt,phone,bodyNo,numberOfDigits,postalCode,address,splitStatus,calculationType,physicalArchiveNo;
    public READINGTBL(){}
    public READINGTBL(String geographicalCode,String sCode,String subscriberId){
        this.geographicalCode=geographicalCode;
        this.sCode=sCode;
        this.subscriberId=subscriberId;

    }
}


and with this code save the data:

SugarContext.init(adapter);
        List<READINGTBL> mySave=new ArrayList<>();
        for(int i=0;i<100;i++) {
            READINGTBL models=new READINGTBL("","","","");
            models.save();
        }


that code must be save 100 record in sugar entity ,but when run this code:

List<READINGTBL> test_find=LOGINTBL.listAll(READINGTBL.class);
        return test_find.size();


return to me 1 always,what happen?how can i solve that problem?thanks.


Solution

  • Without seeing your actual log, I would have to guess that you're running into an issue with your "unique" annotation. With your testing, you are trying to insert records that are exactly the same.

    Instead of just "" for your values, try doing:

    String ts = String.format("val %d", i)
    READINGTBL models=new READINGTBL(ts,ts,ts,ts);