-
Spring에서 Entity 객체와 Entity 객체에 Embed되는 값 객체에 빈(no arguments) 생성자가 필요한 이유는 무엇인가?카테고리 없음 2023. 2. 10. 18:06
In object-oriented programming, a constructor is a special type of method that is used to initialize an object when it is created. An empty constructor is a constructor that takes no arguments and initializes the object with default values.
When you are defining a value object that is included in an entity object, you may want to create an empty constructor for several reasons:
Convenience: An empty constructor makes it easier to create instances of the value object, especially when you don't have any initial data to provide.
Serialization: Some libraries and frameworks may require an empty constructor to be present in order to perform serialization or deserialization of the object.
Object-Relational Mapping (ORM): If you are using an ORM framework, an empty constructor may be required to properly map the value object to a database table.
In general, having an empty constructor is a good practice in Java because it makes the code more flexible and easier to maintain. However, it's also important to consider if the default values make sense for the value object and whether a different constructor should be provided if initial data is required.
Serialization
ORM에서 empty constructor가 필요한 이유는 Reflection API를 이용해 Entity를 Object로 변환하기 때문임
Reflection에 대해 정리해야 함