playframework / play-samples

Play Framework Sample Projects
Creative Commons Zero v1.0 Universal
532 stars 545 forks source link

play-java-ebean-example - JSR-303 validated property 'name' does not have a corresponding accessor #156

Closed pogurek closed 2 years ago

pogurek commented 2 years ago

Hello,

I'm completelly new to play, so I don't understand much of it yet. I wanted to try java+ebean example, but it didn't compile. Since the problem was connected to sbt-play-ebean plugin, I updated it to 6.2.0-RC4. Play version itself was already tha latest 2.8.13.

Then I needed to change deprecated version of EbeanServer to Database and Ebean to DB: I changed this:

private final EbeanServer ebeanServer;

this.ebeanServer = Ebean.getServer(ebeanConfig.defaultServer());

to this:

private final Database ebeanServer;

this.ebeanServer = DB.getDefault();

Now the application runs, but when I want to change any entity in the database, it crashes with this error:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[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)]]

I don't understand the databinder thing. It should work without getters/setters but it is not. List page is rendered well, the problem is in the edit page - none of the fields of the particular computer are prefilled, after saving it crashes.

Thank you for any help in advance!

mkurz commented 2 years ago

@pogurek The sample should work now, please try again.

pogurek commented 2 years ago

I can confirm it works. Thank you. So you added getters/setters everywhere. I thought this was intentional not having them. This thing cannot be used? https://www.playframework.com/documentation/2.8.x/PlayEnhancer Or it is just generally better to stick with getters/setters?

mkurz commented 2 years ago

play-enhancer is not maintained anymore, so I recommend to stop using it and use getters and setters instead (or switch to a 3rd party library like lombok)

pogurek commented 2 years ago

Lombok was another thing I was about to ask. However, I thought there is some internal play mechanism which can deal with accessing entity attributes. Fine for me, though. Thank you!

mkurz commented 2 years ago

In case you run into problems with lombok when using twirl, you might want to put any models that use lombok into a sbt subproject. Let me know if you need any help.

pogurek commented 2 years ago

Despite I like the idea of Lombok very much, I tend to not using it with accessing database. There are more caveats than advantages, imho. I wasted enough time with Lombok + JPA so far. Unless there is generic support for that I'm not going to bother. Maybe if Java Records could be used it might be helpfull. But I'm not an expert. Thanks again!