在尝试调用带有@version注解列的实体存储库中的部分更新时,我收到了一个非法状态异常,消息是micronaut数据的2.4.4版本出现了“@version cannot null”。
实体:
package domain.model.entity.products;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
@Entity
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "product", schema = "products")
public class Product implements Serializable {
@Id
@Column
private String idClient;
@Column
private Integer rating;
@Column
private BigDecimal limitActual;
@Column
private LocalDate dateValidation;
@Column
private Boolean active;
@Version
private Long version;
}
存储库:
package domain.repository.products;
import domain.model.entity.products.Product;
import io.micronaut.data.annotation.Id;
import io.micronaut.data.annotation.Repository;
import io.micronaut.data.annotation.Version;
import io.micronaut.data.jpa.repository.JpaRepository;
import java.math.BigDecimal;
@Repository
public interface ProductRepository extends JpaRepository<Product, String> {
void update(@Id String idClient, BigDecimal limitActual, @Version Long version);
}
当我调试源代码以查找发生的情况时,在类io.micronaut.data.hibernate.operations.HibernateJPAOOperations#bindparameters中,propertypath变量为null,因此该方法无法设置“previousvalue”的值,从而导致错误。
在验证propertypath为何为null时,我发现 preparedQuery.getIndexedParameterPaths()
始终返回null,并且初始化的查询为:
UPDATE domain.model.entity.limit.Product product_ SET product_.limitActual=:p1,product_.version=:p2 WHERE (product_.idClient = :p3 AND product_.version = :p4)
但似乎找不到参数p2。
我做错了什么?
暂无答案!
目前还没有任何答案,快来回答吧!