データベースに接続する簡単なサインアップ フォームを作成しようとしたときに、このエラーが発生しました。Ubuntuを使用しています。これが私のコードです:
Signup.java
package controllers;
import models.User;
import play.data.Form;
import play.mvc.*;
import views.html.signup.*;
import views.html.*;
public class Signup extends Controller{
public static Form<User> form = form(User.class);
public static Result blank(){
return ok(formsu.render(form));
}
public static Result submit(){
Form<User> fillForm = form.bindFromRequest(); // Play mark this line !!!
if(fillForm.hasErrors()) {
return badRequest(formsu.render(fillForm));
}
else{
User created = fillForm.get();
return ok(result.render(created));
}
}
}
ユーザー.java
package models;
import java.util.List;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;
import play.data.validation.Constraints.Email;
import play.data.validation.Constraints.MinLength;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;
@Entity
public class User extends Model{
@Required@NotNull@MinLength(6)
public String username;
@Required@NotNull@MinLength(6)
public String password;
@Required@Email
public String email;
// public User(){}
//
// public User(String username,String password,String email){
// this.username=username;
// this.password=password;
// this.email=email;
// }
public static Finder<Long, User> find = new Finder(Long.class, User.class);
public static List<User> all(){
return find.all();
}
public static void create(User user){
user.save();
}
}
formup.scala.html
@(user : Form[User])
@import helper._
@helper.form(action=routes.Signup.submit){
@inputText(
user("username"),
'_label -> "Username",
'_help -> "Put your username here"
)
@inputPassword(
user("password"),
'_label -> "Password",
'_help -> "Put your password here"
)
@inputPassword(
user("repeatpassword"),
'_label -> "Repeat password",
'_help -> "Put your password again"
)
@inputText(
user("email"),
'_label -> "Email",
'_help -> "Put your email here"
)
<input type="submit" value="Sign up" />
}
ターミナルから:
--- (RELOAD) ---
[info] play - database [default] connected at jdbc:mysql://localhost/login
[info] play - Application started (Dev)
[error] application -
! @6f07fm4f0 - Internal server error, for request [POST /signup] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ValidationException: Call to TraversableResolver.isReachable() threw an exception]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.4]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.4]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.4]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1251) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:448) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:397) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:361) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:313) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:139) ~[hibernate-validator.jar:4.2.0.Final]
Caused by: java.lang.RuntimeException: No @javax.persistence.Id field found in class [class models.User]
at play.db.ebean.Model._idAccessors(Model.java:39) ~[play_2.9.1.jar:2.0.4]
at play.db.ebean.Model._getId(Model.java:52) ~[play_2.9.1.jar:2.0.4]
at play.db.ebean.Model.hashCode(Model.java:183) ~[play_2.9.1.jar:2.0.4]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.buildHashCode(SingleThreadCachedTraversableResolver.java:153) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:114) ~[hibernate-validator.jar:4.2.0.Final]
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver$TraversableHolder.<init>(SingleThreadCachedTraversableResolver.java:96) ~[hibernate-validator.jar:4.2.0.Final]
"index" と "main" html は問題ありません :( 解決するのを手伝ってください。検索してみましたが、このエラーを修正できません。助けてくれてありがとう!!!