How to create an INSERT IGNORE query in Hibernate?

后端 未结 2 1433
终归单人心
终归单人心 2021-01-11 10:41

Hibernate has to make inserts in a table which has an unique field. I want to ignore duplicate entries so that my program keeps running. In MySQL I would simply say IN

2条回答
  •  北海茫月
    2021-01-11 11:40

    Have you tried using the @SQLInsert annotation ? This way, you can overwrite the Hibernate statement with your own custom SQL and use INSERT IGNORE:

    @SQLInsert(sql="INSERT IGNORE INTO CUSTOMER(id,name) VALUES(?,?)")
    class Customer{
       ...
    }
    

提交回复
热议问题