1

I would like to know how the code below affects database creation and data access in Java playframework

public Boolean isactive;

and

Boolean isactive;
marcospereira
  • 11,462
  • 3
  • 42
  • 49
Seroney
  • 785
  • 7
  • 25
  • You might want to read [about PlayEnhancer](https://www.playframework.com/documentation/2.4.x/PlayEnhancer) – AME Jan 25 '16 at 13:21
  • @PiNg2Eiw yap but it doesn't explain the difference – Seroney Jan 25 '16 at 13:28
  • As you clearly see, I didn't create an answer, but a hint that could lead you to an answer and that's the reason why we have comments. – AME Jan 25 '16 at 13:31
  • The only difference is the visibility of the `isactive` variable. Have a look at [this table](http://stackoverflow.com/a/33627846/276052), specifically at the rows for field `i` (which is package protected) and `l` (which is public). – aioobe Jun 10 '16 at 17:05

1 Answers1

2

To understand how this difference affects data access, you must understand how to control access to fields of a class:

  1. https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
  2. In Java, difference between default, public, protected, and private

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

And then, there is the page linked by @PiNg2Eiw that explains how Play Enhancer uses these declarations to automatically add setters and getters:

The enhancer looks for all fields on Java classes that:

  • are public
  • are non static
  • are non final

For each of those fields, it will generate a getter and a setter if they don’t already exist. If you wish to provide a custom getter or setter for a field, this can be done by just writing it, the Play enhancer will simply skip the generation of the getter or setter if it already exists.

Also, database creation is heavily dependent on how you map your model classes. See the following docs:

  1. http://ebean-orm.github.io/docs/mapping/
  2. https://www.playframework.com/documentation/2.4.x/JavaEbean
Community
  • 1
  • 1
marcospereira
  • 11,462
  • 3
  • 42
  • 49