[英]Play framework - can not connect to postgresql
I start to use postgresql in my play app and able to connect to play's default database and do some select and update. 我开始在我的游戏应用程序中使用postgresql,并且能够连接到游戏的默认数据库并进行一些选择和更新。 But there re always errors when I turn to use postgresql. 但是当我转向使用postgresql时,总会出现错误。 Please give me some advice.Thank you. 请给我一些建议。谢谢。 I already added postgresql-42.0.0.jar in /lib. 我已经在/ lib中添加了postgresql-42.0.0.jar。
error in this line:"u1.save();": [PersistenceException: Error getting sequence nextval] 此行中的错误:“ u1.save();”:[PersistenceException:获取序列nextval时出错]
application.conf:
db.default.driver=org.postgresql.Driver
db.default.url="postgres://postgres:123456@localhost/testing"
#db.default.url="postgres://user:password@servername/dataBaseName"
# Ebean configuration
ebean.default="models.*"
build.sbt:
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "42.0.0 JDBC 42",
javaJdbc,
javaEbean,
cache
)
Application.java:
public class Application extends Controller {
public static Result index() {
User u1 = new User();
User u2 = new User();
u1.name = "Mm";
u2.name = "Nn";
u1.save();
u2.save();
return ok("saved");
}
public static Result allUser() {
List<User> users = User.findAll();
return ok(findalluser.render(users));
}
}
If your error is really [PersistenceException: Error getting sequence nextval] it means that you did not create correctly your sequence generator that is responsible to increment automatically your id`s. 如果您的错误确实是[PersistenceException:获取序列nextval错误],则意味着您没有正确创建负责自动递增ID的序列生成器。
On your model you gotta annotate your class with this annotation on your primary key: 在模型上,您必须在主键上使用以下注释来注释您的类:
@Entity
public class User extends Model {
@Id //makes it a primary key
@GeneratedValue //creates the sequence generator
public Long id;
}
我认为应该有端口号:
db.default.url="postgres://postgres:123456@localhost:5432/testing"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.