How to insert new items with Hibernate?

前端 未结 3 533
花落未央
花落未央 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.

    0 讨论(0)
  • 2021-01-02 02:51

    I accidentally removed hibernate_sequence table in my db. Change:

    spring.jpa.hibernate.ddl-auto=none
    

    to

    spring.jpa.hibernate.ddl-auto=create
    

    In your application.properties file so Hibernate could recreate this table by himself

    0 讨论(0)
  • 2021-01-02 02:58

    If someone else is struggling with this error, I fixed it by removing

    <prop key="hibernate.id.new_generator_mappings">true</prop>
    

    From hibernate properties.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题