自定义SequenceStyleGenerator导致saveOrUpdate错误

时间:2018-06-05 08:33:34

标签: hibernate

我已经实现了一个自定义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

0 个答案:

没有答案