1
@Entity
@Table
public class Page {

    ...

    private String URL;

    public void setURL(String URL) {
         this.URL = URL; 
    }

   public String getURL() {
       return URL
   }
}

The URL is mapped to one field in a table. I set a break point in setURL() method, but the program doesn't break when debugging; then I changed the break point to getURL() method, the break point was triggered.

Does this mean that the setURL method isn't used or triggered at all? The front view doesn't accept user's input as URL value, and the URL is retrieved from database. If that's the case, do I need the setURL() method at all?

marlon
  • 6,029
  • 8
  • 42
  • 76

2 Answers2

0

If the field is actually set but you can't catch that it in debug, it might be because it is set through reflection instead of using the setter.

Bax
  • 4,260
  • 5
  • 43
  • 65
  • What's the expected behavior? – marlon Mar 02 '16 at 01:02
  • From what you've posted in the question, where you do not specify the access type nor do you annotate your fields/methods it will be reflection. – Bax Mar 02 '16 at 01:12
0

JPA lets you define the access type as either field or property. By default this is set based on whether the @Id annotation is placed on the field or the getter.

If the access type is field then the JPA implementation will use reflection to use the fields directly even if they are private.

more reading: Other Answer, JPA Access Type

Community
  • 1
  • 1
John Scattergood
  • 1,032
  • 8
  • 15