0
votes

I have been trying to learn and creating a sample project using GWT/GAE/GoogleDatastore.

Am just trying to figure out what would be the best way to design the data model for a learning management system. Let's say in the traditional way the following are the entities.....

User
Role

UserCourses

Courses
Subjects
Materials

User is one to one to Role
Courses is one to many with Subjects
Subjects is one to many with Materials
Users is Many to Many with Courses using UserCourses

Can someone guide me what would be the best possible way to represent this in JDO ?

---> Extension of the question.

Thank You Shifty, but am completely stuck with unowned relationship model... trying/struggling to come out of the traditional relational model.

Let me take the simple Subjects vs Materials

Am trying out the following model,

@PersistenceCapable(identityType = IdentityType.APPLICATION) public class Subjects {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private List<Materials> materials;

}

public class Materials{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private String materialName;
@Persistent
private String author;
@Persistent
private String materialType;
@Persistent
private String url;

}
When i try to save the materials first and then assigning that object into subjects is having issues. As i read, you cannot assign the child to a parent which is already persisted without parent.
Sometimes it is possible to add materials without assigned to the Subjects, but can get assigned later on.

1

1 Answers

0
votes

if you want to make a many-to-many relationship with GAE and JDO you have to store a list of the keys in the models.

User Model

import java.util.Set;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class User {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private Set<Key> courses;
}

Courses Model

   import java.util.Set;
    import com.google.appengine.api.datastore.Key;

    @PersistenceCapable
    public class Courses {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;
        @Persistent
        private Set<Key> users;
    }

this way you don't need the UserCourses class.

EDIT:

If you use

@Persistent
private List<Materials> materials;

you work with a owned relationship model. this way you can not persist the model first and then add this to the subject model and the persist the subject model. Just add the not persistent material to the materials list of the subject model and persist the subject model. this will also save the materials.

maybe I could the question wrong but I hope this helps.