我已经实现了一个自定义SequenceStyleGenerator
,允许直接ID分配(另外)。这种方法符合here的规定。但是当我尝试saveOrUpdate
(Hibernate)包含这个自定义生成器的实体时,它会导致麻烦
ID。抛出以下异常:
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
当我从我的实体类中删除生成器时,这不会发生。
我怎样才能解决这个问题?我仍然想使用这样的id生成器和saveOrUpdate
方法。
一个这样的实体类:
@GenericGenerator(name = FIX_OR_AUTO, strategy = AssignOrAutoGenerator.QN)
@Entity data class PoiCity(
@GeneratedValue(generator = FIX_OR_AUTO)
@Id val poiCityId: Int? = null,
var zipCode: String,
@ElementCollection
@CollectionTable(name = "PoiCityName", foreignKey = ForeignKey(name = "none"), joinColumns = [JoinColumn(name = "poiCityId")])
@MapKeyColumn(name = "locale")
var cityName : Map<String, String>,
@ManyToOne @JoinColumn(name = "countryId")
var country: Country): Serializable