我正在尝试使用版本字段使用乐观锁定,并且当我从jpa存储库调用save时没有抛出异常。我是Spring和hibernate的新手,我担心我的设置不正确。
我使用的库是: hibernate4-maven-plugin version 1.0.2 hibernate-jpa02.0 1.0.1 spring-data-jpa version 1.3.4
所以我的实体是这样设置的:
@Entity
public class MyEntity
{
@Id
protected Long id;
@Version
protected Long version;
在更新到版本2.1.5之后,put请求不再用不可变实体更新实体。
将请求放在2.0.3上,而不是在2.1.4和2.1.5上。然而,使用Patch方法工作得很好。
由于我是在Kotlin工作,所以我的代码是用Kotlin编写的,但是我也可以用Java实体来再现这个代码:
鉴于这些实体:
@Entity
data class MyEntityKt(
@Id
@GeneratedValue
val id: UUID? = null,
@Version
val version: Long = 0,
val name: String =
假设我有一份实体清单:
List<SomeEntity> myEntities = new ArrayList<>();
SomeEntity.java:
@Entity
@Table(name = "entity_table")
public class SomeEntity{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private int score;
public SomeEntity() {}
public SomeEntity(long id