greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

How to use inner class about greenDAO with version 3.x about annotation?🆘 #509

Closed baoyachi closed 8 years ago

baoyachi commented 8 years ago

Hi, I just have a problem with greenDAO with version 3.x. Look below example

public class RecordBean {

    private String name;
    private String idCard;
    private String address;
    private PointBean pointBean;
    private List<StepBean> stepBean;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public PointBean getPointBean() {
        return pointBean;
    }

    public void setPointBean(PointBean pointBean) {
        this.pointBean = pointBean;
    }

    public List<StepBean> getStepBean() {
        return stepBean;
    }

    public void setStepBean(List<StepBean> stepBean) {
        this.stepBean = stepBean;
    }

    public static class PointBean {
        private double altitude;
        private double distance;
        private double latitude;
        private double longitude;
        private long startTime;
        private long endTime;

        public double getAltitude() {
            return altitude;
        }

        public void setAltitude(double altitude) {
            this.altitude = altitude;
        }

        public double getDistance() {
            return distance;
        }

        public void setDistance(double distance) {
            this.distance = distance;
        }

        public double getLatitude() {
            return latitude;
        }

        public void setLatitude(double latitude) {
            this.latitude = latitude;
        }

        public double getLongitude() {
            return longitude;
        }

        public void setLongitude(double longitude) {
            this.longitude = longitude;
        }

        public long getStartTime() {
            return startTime;
        }

        public void setStartTime(long startTime) {
            this.startTime = startTime;
        }

        public long getEndTime() {
            return endTime;
        }

        public void setEndTime(long endTime) {
            this.endTime = endTime;
        }
    }

    public static class StepBean {
        private double stepDistance;
        private double stepTime;
        private double duration;

        public double getStepDistance() {
            return stepDistance;
        }

        public void setStepDistance(double stepDistance) {
            this.stepDistance = stepDistance;
        }

        public double getStepTime() {
            return stepTime;
        }

        public void setStepTime(double stepTime) {
            this.stepTime = stepTime;
        }

        public double getDuration() {
            return duration;
        }

        public void setDuration(double duration) {
            this.duration = duration;
        }
    }
}

So,how to add annotation with greenDAO in version 3.x . I am confused. So, I need help

greenrobot-team commented 8 years ago

You can either populate this data yourself and annotate those fields with @Transient so they will not get stored.

Or you use a converter for your custom types PointBean and StepBean. -ut