Question

I have two entity classes, project and projectList. The ProjectList has the attributes id and a HasMap holding a list of projects. I'm able to perform the INSERT operation without any error, but while retrieving my HashMap list is null.Tried inserting an arrayList, this also returns null.

Is there support for persisting a collection class like a HashMap or ArrayList in SugarORM ?

Kindly help. Thanks.

ProjectList Entity Class.

public class ProjectList extends SugarRecord<ProjectList> {
private int projectListId;
private HashMap<String, Project> projects;

/** Empty Constructor */
public ProjectList(Context context) {
    super(context);
}

public ProjectList(Context context, int projectId,
        HashMap<String, Project> projects) {
    super(context);
    this.projectListId = projectId;
    this.projects = projects;
}

/**
 * @return the projectListId
 */
public int getProjectListId() {
    return projectListId;
}

/**
 * @param projectListId
 *            the projectListId to set
 */
public void setProjectListId(int projectListId) {
    this.projectListId = projectListId;
}

/**
 * @return the projects
 */
public HashMap<String, Project> getProjects() {
    return projects;
}

/**
 * @param projects
 *            the projects to set
 */
public void setProjects(HashMap<String, Project> projects) {
    this.projects = projects;
}

}
Was it helpful?

Solution

SugarORM does not support saving HashMaps in the database.

Consider rethinking your database structure so that you can link projectlists with projects using queries.

More information and some workarounds can be found here: https://github.com/satyan/sugar/issues/60

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top