Play 2.0 Morphine Design with a Mongod

This is my first time using MongoDb and morphia, and I'm pretty new to databases in general. I am wondering how I should organize my morphine code. I studied usage DAO, as the morphine documentation says , but as they seem to do it, I will have to create a DAOmodel for each object that I have. I liked the game methodology, which basically provides the model’s objects with the opportunity to save themselves, but I only have vague ideas about what is happening under the hood here, so I'm not sure how to achieve this with morphine, or if it is even desirable to do so. The code that I still looked like this for the skeleton of the user model.

@Entity("user")
public class User extends BasicDAO<User, ObjectId>{
    @Id ObjectId id;

public String firstName;

public String lastName;

public String email;

@Indexed public String username;

public String password;

public User(Mongo mongo, Morphia morphia){
    super(mongo, morphia, "UserDAO");
}
public User(){
    this(DBFactory.getMongo(), DBFactory.getMorphia());
}

public void save(){
    ds.save(this);
}

public static User findByUsername(String uname){
    return DBFactory.getDatastore().find(User.class, "username =", uname).get();
}

public static boolean authenticate(String uname, String pword){
    User user = DBFactory.getDatastore().createQuery(User.class).filter("username", uname).filter("password", pword).get();
    if(user == null)
        return false;
    else
        return true;
}
}

StackOverflowException, , , , ?

DBFactory mongodb.

+3
2

Marphia play framework 2.x. , , . , marphia: https://github.com/czihong/playMongoDemo

+1

All Articles