Hibernate: ids for this class must be manually assigned before calling save()

前端 未结 2 2020
青春惊慌失措
青春惊慌失措 2021-02-01 12:33

I am having some problems with Hibernate and the oneToMany mapping.

Here is my function:

        Location location = new Location();
                


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 13:10

    Assign primary key in hibernate

    Make sure that the attribute is primary key and Auto Incrementable in the database. Then map it into the data class with the annotation with @GeneratedValue annotation using IDENTITY.

    @Entity
    @Table(name = "client")
    data class Client(
            @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private val id: Int? = null
    )
    

    GL

    Source

提交回复
热议问题