@Entity
A Class that will be mapped to an actual DB Table
Also called an Entity Class
By default, the Class's
Camel Casenaming is matched to table names usingUnderscore(_)namingex)
SalesManager.java β sales_manager
Setter methods should not be created in Entity Classes
Why?
Because it is not clearly distinguishable in code when and where the instance values of the class should change
If field value changes are needed, a method with a clear purpose and intention should be added
ex) A function that sets the order status β setStatus (x), cancelOrder (o)
Entity Classes basically populate values through a
constructorand INSERT into the DBWhen value changes are needed, a public method corresponding to the event is called to make the change
A
Buildercan be used instead of a constructor to make it clearer which field gets which valueex)
In the code below, the results of Example(a,b) and Example(b, a) would be different
public Example(String a,String b) { this.a=a; this.b=b; }Using a
Buildermakes the order irrelevant
Last updated