Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在本地主机上使用Ebean和PostgreSQL播放框架_Postgresql_Playframework 2.0_Ebean - Fatal编程技术网

在本地主机上使用Ebean和PostgreSQL播放框架

在本地主机上使用Ebean和PostgreSQL播放框架,postgresql,playframework-2.0,ebean,Postgresql,Playframework 2.0,Ebean,我是Play Framework、Ebeans和PostgreSQL的新手,几天来一直试图找到正确的答案,但最后我没有找到解决问题的好办法。也许这是一个noob问题,但对我来说,知道我做错了什么并为我的问题找到正确的解决方案是很重要的。这对我真的很有帮助。问题是,当我启动localhost从“localhost/9000/users”上的数据库获取值时,总是会收到此错误消息 执行异常 [PersistenceException:查询抛出SQLException:错误:关系“用户”不存在位置:61

我是Play Framework、Ebeans和PostgreSQL的新手,几天来一直试图找到正确的答案,但最后我没有找到解决问题的好办法。也许这是一个noob问题,但对我来说,知道我做错了什么并为我的问题找到正确的解决方案是很重要的。这对我真的很有帮助。问题是,当我启动localhost从“localhost/9000/users”上的数据库获取值时,总是会收到此错误消息

执行异常

[PersistenceException:查询抛出SQLException:错误:关系“用户”不存在位置:61个绑定值:[]查询是:从“用户”t0中选择t0.user\u id作为c0,t0.name作为c1,t0.email作为c2] 在第12行的/../app/controllers/Application.java中

所以, 我在本地主机上运行了一个PostgreSQL数据库。 我用我自己的模式“test_schema”代替公共模式。 我还创建了一个名为“users”的表,它有三个属性(userid、name、email)

我使用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.*"
我禁用了evolution,因为DB已经存在,并且还有一些条目

因此,我创建了如下实体类:

@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;
}

}
}

而conf/routes有以下条目:

GET     /users                          controllers.Application.getAllUsers()

原因可能是什么?他们有什么建议可以让它发挥作用吗?

在开始的时候突出你的问题也很好。问题是DB得到了一个名为“user\u ID”的表。这使得Eben和后面的小写系统出现了问题。所有选项卡都应使用小写字母命名!您确实应该尊重基本的Java约定。重命名类
User
,将
User\u ID
重命名为
userId
。如果表中的列是
user\u ID
,并且您无法更改它,请将
@column(name=“user\u ID”)
添加到类中的属性中。
public static Result getAllUsers(){
   return ok(Json.toJson(users.find.all()));
GET     /users                          controllers.Application.getAllUsers()