How to insert new items with Hibernate?

前端 未结 3 598
花落未央
花落未央 2021-01-02 02:17

I have an entity class called Task which is mapped in hibernate.

I\'m able to fetch existing items belonging to this class correctly, so I don\'t think

3条回答
  •  误落风尘
    2021-01-02 02:51

    Got this to work with the help of this link: http://www.coderanch.com/t/487173/ORM/databases/hibernate-sequence-exist

    Apparently hibernate looks for sequence tables for generating the id. Setting the following:

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    

    on the id, causes it to use the underlying db's auto increment and not try to generate the id itself, and now it works.

提交回复
热议问题