一旦我尝试使用 sql 语句插入将数据保存到数据库中,这就是问题所在。
我的功能是这样的:
public void save(){
JPA.em().persist(this);
}
和
public static Result registered() {
Form<User> requestform = form(User.class).bindFromRequest();
if(requestform.hasErrors()){
return badRequest("<p>fehlerhafte eingabe!</p>").as("text/html");
} else {
User user = requestform.get();
String fullname = user.fullname;
String email = user.email;
String password = user.password;
String username = user.username;
new User(username, password, fullname, email).save();
}
return redirect(controllers.routes.Application.index());
}
感谢帮助
最佳答案
就像调试消息所说的那样,您没有将实体管理器绑定(bind)到您的方法,因为它们没有标记为事务。
@play.db.jpa.Transactional
public static Result registered() {
此外,如果您使用的是 EBean,您可以只为您的 User 类扩展 Model,它带有许多方便的内置函数供数据库使用,请参阅此处的文档:http://www.playframework.org/documentation/2.0.1/JavaEbean
关于database - [RuntimeException : No EntityManager bound to this thread. Try to annotate your action method with @play.db.jpa.Transactional],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11101593/