echo
09/08/2023, 7:47 AM@ID
of an entity class?
And @Id
property is generated by database autoincrement.
In this question, pk is not-null in the database, and there is discussion within the team about what value should be set as default before Entity persisted, so we are also asking the community's opinion.
In this case, I dont discuss about using constructor each time when create instance.
1. nullable - var
@Entity
class Entity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
)
2. nullable - val
@Entity
class Entity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null
)
3. non-null - var
@Entity
class Entity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long = 0L
)
4. non-null - val
@Entity
class Entity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0L
)
Please share your voice and opinion free!LeoColman
09/08/2023, 11:30 PM