乐观锁定:不受支持的版本类型 long
Optimistic Locking: unsupported Version type long
我正在尝试将乐观锁定与 Micronaut 数据和 Kotlin 结合使用,但不幸的是它失败并出现异常:
14:33:32.113 [default-nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: An error occurred invoking pre-persist event listeners: Unsupported @Version type: long
io.micronaut.data.event.PersistenceEventException: An error occurred invoking pre-persist event listeners: Unsupported @Version type: long
at io.micronaut.data.runtime.event.EntityEventRegistry.prePersist(EntityEventRegistry.java:92)
at io.micronaut.data.hibernate.event.EventIntegrator.lambda$integrated2e46a6(EventIntegrator.java:77)
at org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:227)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:100)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.lambda$executeActions(ActionQueue.java:478)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1362)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:453)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3212)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2380)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access0(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
...
我的设置如下所示(应该与文档非常相似):
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table
import javax.persistence.Version
@Entity
@Table(name = "invoice_queue")
data class InvoiceQueueEntity(
@Id
@GeneratedValue
var id: Long = 0,
...(things left out for privacy reasons)...
@Version
var version: Long = 0L,
)
创建 table 的迁移是:
create table invoice_queue
(
id int8 not null,
primary key (id)
);
create sequence hibernate_sequence start 1 increment 1;
alter table if exists invoice_queue
add column version int8 not null default 0;
我是不是漏掉了什么?
如果您确定您使用的是 javax.persistence.Version
而不是 io.micronaut.core.version.annotation.Version
,那么问题可能是 java 字段具有原始类型。
如果你让它可以为空,你应该得到盒装类型。尝试:
var version: Long? = 0L
我正在尝试将乐观锁定与 Micronaut 数据和 Kotlin 结合使用,但不幸的是它失败并出现异常:
14:33:32.113 [default-nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: An error occurred invoking pre-persist event listeners: Unsupported @Version type: long
io.micronaut.data.event.PersistenceEventException: An error occurred invoking pre-persist event listeners: Unsupported @Version type: long
at io.micronaut.data.runtime.event.EntityEventRegistry.prePersist(EntityEventRegistry.java:92)
at io.micronaut.data.hibernate.event.EventIntegrator.lambda$integrated2e46a6(EventIntegrator.java:77)
at org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:227)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:100)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.lambda$executeActions(ActionQueue.java:478)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1362)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:453)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3212)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2380)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access0(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
...
我的设置如下所示(应该与文档非常相似):
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table
import javax.persistence.Version
@Entity
@Table(name = "invoice_queue")
data class InvoiceQueueEntity(
@Id
@GeneratedValue
var id: Long = 0,
...(things left out for privacy reasons)...
@Version
var version: Long = 0L,
)
创建 table 的迁移是:
create table invoice_queue
(
id int8 not null,
primary key (id)
);
create sequence hibernate_sequence start 1 increment 1;
alter table if exists invoice_queue
add column version int8 not null default 0;
我是不是漏掉了什么?
如果您确定您使用的是 javax.persistence.Version
而不是 io.micronaut.core.version.annotation.Version
,那么问题可能是 java 字段具有原始类型。
如果你让它可以为空,你应该得到盒装类型。尝试:
var version: Long? = 0L