Mike
Mike

Reputation: 67

Playframework 2 - creating a sql query

Im trying to create a simple query, for some reason all combinations i try, throws the following exception

play - Cannot invoke the action, eventually got an error: java.lang.RuntimeException: get uid on [models.User] type[java.lang.String] threw error.

I Have a User model and a Project model. I want a query that searches for a project that belongs to user X and has name Y.

the code i tried that throws the exception above:

Project uploadProject = Project.find.where().add(Expr.and(Expr.eq("owner", curUser.email),Expr.eq("name", projectName))).findUnique();

also tried

Project uploadProject2 = Project.find.where().eq("owner", curUser.email).eq("name", projectName).findUnique();

what is the correct way to do this, I've searched in play documentation but it will only refer to simple searches none that require more then 1 parameter to search by.

Upvotes: 1

Views: 201

Answers (1)

Mike
Mike

Reputation: 67

The exception was due to comparing wrong field types. owner field is of User type, i compared it to the user email string.

in my case

.eq("owner", curUser.email)

should of been:

.eq("owner.email", curUser.email)

Upvotes: 1

Related Questions