Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:45:41+00:00 2026-06-17T11:45:41+00:00

In Play Framework 1.x, the convention is to use public fields on Java classes.

  • 0

In Play Framework 1.x, the convention is to use public fields on Java classes. The justification for this is because of how the Play Properties Enhancers work as described here: http://www.playframework.org/documentation/1.2.4/model

In a nutshell, public fields are ‘ok’ because Play auto-generates setters and getters at runtime. That makes sense to me and there are other questions that cover that.

Play Framework 2.0 works very differently. There is no “Properties Simulation” capability. Maybe they are looking at adding this later but I could not find anything to suggest this. Without the properties simulation, the original justification for using all public fields is gone. The Play Framework 2.0 samples still use public fields though:
http://www.playframework.org/documentation/2.0/JavaEbean

Why are public fields still recommended for playframework 2.0? Is this just a habit of developers on the old version of play who created the samples or is there another reason why the use of public fields is still recommended in Play 2.0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:45:42+00:00Added an answer on June 17, 2026 at 11:45 am

    Looking in the documentation: https://github.com/playframework/Play20/wiki/JavaEbean, Play will generate missing accessors for us.

    However they are caveats with this technique, the most will be that the ebean instrumentation won’t work on generate get/setter… and so problem might happen (transaction, …)

    Here is the related quote:

    Play has been designed to generate getter/setter automatically, to ensure compatibility with libraries that expect them to be available at runtime (ORM, Databinder, JSON Binder, etc). If Play detects any user-written getter/setter in the Model, it will not generate getter/setter in order to avoid any conflict.

    Caveats:

    (1) Because Ebean class enhancement occurs after compilation, do not expect Ebean-generated getter/setters to be available at compilation time. If you’d prefer to code with them directly, either add the getter/setters explicitly yourself, or ensure that your model classes are compiled before the remainder of your project, eg. by putting them in a separate subproject.

    (2) Enhancement of direct Ebean field access (enabling lazy loading) is only applied to Java classes, not to Scala. Thus, direct field access from Scala source files (including standard Play 2 templates) does not invoke lazy loading, often resulting in empty (unpopulated) entity fields. To ensure the fields get populated, either (a) manually create getter/setters and call them instead, or (b) ensure the entity is fully populated before accessing the fields.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the Play Framework 2.0 tutorial for Java and get this error when
In play framework 1, you could use in the routes file something like this
Using Play Framework, you can do something like this: public static void mymethod() {
I recently stumbled upon Play framework while evaluating frameworks to use in a project.
I have Play framework 2.0.4 installed. For the java app I have, I want
I use the in-memory database that comes with Play Framework, when I have db=mem
Using play framework 2.0 in Java mode and I want to pass a list
I'm learning the Play framework. I'm cunfused about three classes which represent a warehouse-stock
I'm building some crude CMS-like functionality (to get acquinted with Play Framework). For this
I just started to use the Play framework and Scala. What does body: =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.