我是Play-Framework,Ebeans和PostgreSQL的新手,并试图找到正确的答案,但最后我没有找到任何解决我问题的好方法。也许这是一个noob问题但对我来说重要的是要知道我做错了什么并为我的问题找到了正确的解决方案。这真的对我很有帮助。问题是,当我启动localhost以从" localhost / 9000 / users "
获取数据库中的值时,我总是收到此错误消息执行例外
[PersistenceException:Query抛出SQLException:ERROR:relation" users"不存在位置:61绑定值:[]查询为:选择t0.user_id为c0,t0.name为c1,t0.email为c2,来自" users" t0] 在第12行的/.../app/controllers/Application.java中。
9 public class Application extends Controller {
10
11 public static Result getAllUsers(){
12 return ok(Json.toJson(users.find.all()));
13 }
14
15 }
所以, 我有一个在localhost上运行的PostgreSQL-DB。 我使用名为" test_schema "的公共架构来代替公共架构。 我还创建了一个名为" users "具有三个属性(user_ID,名称,电子邮件)。
我使用Play Framework 2.3.0。并像这样配置/application.conf:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/test_db"
db.default.schema=test_schema
db.default.user="postgres"
db.default.password="12345"
db.default.logStatements=true
evolutionplugin=disabled
ebean.default="models.*"
我禁用了进化,因为数据库已经存在并且还有一些条目。
所以我创建了这样的Entity-Class:
@Entity
@Table(name="\"users\"")
public class users extends Model{
public users(int user_ID, String name, String email){
this.user_ID = user_ID;
this.name = name;
this.email = email;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int user_ID;
@Required
private String name;
@Required
private String email;
public static Finder<Integer, users> find = new Finder<Integer, users>(Integer.class, users.class);
public static List<users> all() {
return find.all();
}
public int getUserID() {
return user_ID;
}
public void setUserID(int userID) {
this.user_ID = userID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
在我的Controller-Class中我只有这个方法:
public static Result getAllUsers(){
return ok(Json.toJson(users.find.all()));
}
conf / routes有这个条目:
GET /users controllers.Application.getAllUsers()
可能是什么原因?他们的任何建议是否有效?