-2

Can someone clarify my doubt.

public class MyClass{
    private String name;

    public void setName(String name) {
         this.name = name;
    }

     public String getName() {
          return name + " Hello";
     }
      public static void main() {
             User u = new User();
             u.setName("Yethendra");
      }
}

If I try to insert this record into a database using hibernate, what is the value that will be inserted for the name column?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Assumming you are using save(user) It will persist what you have on the name variable.

The only way to modify your variable is calling the setName() method. getName() never reassign the name variable.

sirandy
  • 1,834
  • 5
  • 27
  • 32
  • What will be used (field or getter) depends on access mode for that particular entity: https://stackoverflow.com/questions/2676689/does-hibernate-always-need-a-setter-when-there-is-a-getter – Ivan Nov 16 '18 at 18:32