Java entity - why do I need an empty constructor?

后端 未结 8 845
情歌与酒
情歌与酒 2020-12-08 07:23

This might sound stupid to you, but why do I need to define an empty constructor in my @Entitys?

Every tutorial I saw said : every entity needs an empty

8条回答
  •  感情败类
    2020-12-08 07:50

    From the JPA tag, I suppose that you are working with Java beans. Every bean needs to have the following properties:

    1. Getters and setters for all its main instance variables.

    2. An empty constructor.

    3. All its instance variables should preferably be private.

    Thus the statement : "every entity needs an empty constructor".

提交回复
热议问题