2014年8月5日 星期二

[Hibernate]insert one record multiple times

前言:

在hibernate底下,做insert同一筆record多次時,遇到以下問題


(1)如果同一筆資料insert兩次,會變成第二次update同一筆資料


(2)如果把id設為null,再save會跳出下面exception
entifier of an instance of was altered from to null

(3)如果把id設為0或其他值,再save會跳出下面exception
identifier of an instance of was altered from to n


解決方式:
      先new Entity,copyProperties後再save

Reference:http://my.oschina.net/liangzhenghui/blog/194939