2015-11-24 61 views
1

我有一個玩! 2.2我升級到2.5的項目。但是,自升級以來,我遇到了數據庫問題,它看起來是配置錯誤或遺漏。 看來,更改沒有保存,並且表單不工作。遊戲中的表格! 2.5

我宣佈ebeans指令在application.conf

ebean.default= ["models.*"] 

和關閉過程加載模塊的plugins.sbt和build.sbt。 我的代碼的例子,我有一個設備:

@Entity 
public class Device extends Model { 

    @Id 
    public Long id; 

    @Constraints.Required 
    public String name; 

    @Constraints.Required 
    public String ipAddress; 

    @Constraints.Required 
    public String uniqueId; 

    @OneToMany(mappedBy="device") 
    public List<Sensor> sensors = new ArrayList<>(); 

    @OneToMany(mappedBy="device") 
    public List<Action> actions = new ArrayList<>(); 

    @OneToOne 
    public LogItem latestError; 

    @Version 
    public Timestamp lastUpdate; 

    public boolean debugMode; 

    public boolean statusLed; 

    public static Finder<Long, Device> find = new Finder<Long, Device>(
      Long.class, Device.class 
    ); 

    public List<ValidationError> validate() { 
     /* 
     List<ValidationError> errors = new ArrayList<ValidationError>(); 
     if (User.byEmail(email) != null) { 
      errors.add(new ValidationError("email", "This e-mail is already registered.")); 
     } 
     return errors.isEmpty() ? null : errors; 
     */ 
     return null; 
    } 
} 

這是我的控制器:

public static Result add() { 
    Form<Device> deviceForm = Form.form(Device.class); 
    return ok(editView.render(deviceForm, null)); 
} 

而這個模板:

@(deviceForm: Form[Device], device: Device) 

    @if(deviceForm.hasGlobalErrors) { 
     <ul> 
     @deviceForm.globalErrors.foreach { error => 
      <li>error.message</li> 
     } 
     </ul> 
    } 


    @main("Edit a device") { 

     @if(deviceForm("id").value == "" || deviceForm("id").value == null) { 
      <h2>Add the device</h2> 
     } else { 
      <h2>Update the device</h2> 
     } 

     @helper.form(action = routes.Devices.update()) { 

      @helper.inputText(
       deviceForm("name"), 
       '_label -> "Device name" 
      ) 

      @helper.inputText(
       deviceForm("ipAddress"), 
       '_label -> "IP Address" 
      ) 

      @helper.inputText(
       deviceForm("uniqueId"), 
       '_label -> "Unique ID" 
      ) 

      @helper.checkbox(
       deviceForm("statusLed"), 
       '_label -> "Status light" 
      ) 

      @helper.checkbox(
       deviceForm("debugMode"), 
       '_label -> "Debug mode" 
      ) 

      @if(device != null){ 
      <div>Sensors:</div> 
      <div> 
      <table class="adminTable"> 
      @for(sensor <- device.sensors) { 
       <tr> 
       <td>@sensor.value</td> 
       <td><a href="@routes.Sensors.edit(sensor.id)">edit<a/> | <a href="@routes.Sensors.delete(sensor.id)">delete</a></td> 
       </tr> 
      } 
      </table> 
      </div> 
      } 
      @if(deviceForm("id").value != "" && deviceForm("id").value != null) { <div>Last updated: @device.lastUpdate.format("dd MMM yy - HH:mm:ss")</div> } 
      <div> 
       <input type="hidden" name="id" value="@deviceForm("id").value"> 
       <input type="submit" value="Submit"> 
      </div> 
     } 

     <a href="@routes.Devices.index()">Cancel</a> 
    } 

當我填寫的所有字段和點擊'提交'我得到以下錯誤:

[error] p.c.s.n.PlayDefaultUpstreamHandler - Cannot invoke the action 
java.lang.IllegalStateException: JSR-303 validated property 'name' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access) 
    at play.data.Form.bind(Form.java:372) ~[play-java_2.11-2.4.4.jar:2.4.4] 
    at play.data.Form.bindFromRequest(Form.java:222) ~[play-java_2.11-2.4.4.jar:2.4.4] 
    at controllers.Devices.update(Devices.java:44) ~[classes/:na] 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na] 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na] 
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) ~[play_2.11-2.4.4.jar:2.4.4] 
    at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:127) ~[play_2.11-2.4.4.jar:2.4.4] 
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:70) ~[play_2.11-2.4.4.jar:2.4.4] 
    at play.GlobalSettings$1.call(GlobalSettings.java:67) ~[play_2.11-2.4.4.jar:2.4.4] 
    at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[play_2.11-2.4.4.jar:2.4.4] 
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'name' of bean class [models.Device]: Bean property 'name' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? 
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:731) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:722) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
    at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
    at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:108) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
    at play.data.Form.bind(Form.java:366) ~[play-java_2.11-2.4.4.jar:2.4.4] 
    at play.data.Form.bindFromRequest(Form.java:222) ~[play-java_2.11-2.4.4.jar:2.4.4] 
    at controllers.Devices.update(Devices.java:44) ~[classes/:na] 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na] 
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na] 
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) ~[play_2.11-2.4.4.jar:2.4.4] 
[error] application - 

我也有一個預先填充的記錄,當我編輯它時,表單域都是空的。但是,調試顯示數據在那裏,並且從對象本身生成的「傳感器」列表也出現。

所以在我的Play配置中一定有問題! 2.5,但我無法弄清楚什麼。

回答

1

看來這是一個緩存問題。使用:

activator clean 
activator clean-files 

和重建項目修復了這個問題。