quarkus和休眠映射(现场访问)

时间:2019-11-28 19:23:32

标签: quarkus

我将一个在JEE wildfly中工作过的实体移到了quarkus:

@Entity
@Getter
@Setter
public class Item {

@Column(name = "archived")
private OffsetDateTime archived;

public boolean isArchived() {
    return archived != null;
}
}

在开发模式下运行后,出现此错误:


Caused by: org.hibernate.MappingException: 
In trying to locate getter for property [archived], 
Class [com.Item] 
defined both a `get` [public java.time.OffsetDateTime com.Item.getArchived()] 
and `is` [public boolean com.Item.isArchived()] variant
    at org.hibernate.internal.util.ReflectHelper.checkGetAndIsVariants(ReflectHelper.java:538)
    at org.hibernate.internal.util.ReflectHelper.verifyNoGetVariantExists(ReflectHelper.java:562)
    at org.hibernate.internal.util.ReflectHelper.getGetterOrNull(ReflectHelper.java:502)
    at org.hibernate.internal.util.ReflectHelper.findGetterMethod(ReflectHelper.java:424)
    at org.hibernate.internal.util.ReflectHelper.getterMethodOrNull(ReflectHelper.java:571)
    at org.hibernate.property.access.internal.PropertyAccessMixedImpl.getAccessType(PropertyAccessMixedImpl.java:97)
    at org.hibernate.property.access.internal.PropertyAccessMixedImpl.<init>(PropertyAccessMixedImpl.java:47)
    at org.hibernate.property.access.internal.PropertyAccessEnhancedImpl.<init>(PropertyAccessEnhancedImpl.java:28)
    at org.hibernate.property.access.internal.PropertyAccessStrategyEnhancedImpl.buildPropertyAccess(PropertyAccessStrategyEnhancedImpl.java:27)
    at org.hibernate.mapping.Property.getGetter(Property.java:311)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:255)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:142)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:59)
    ... 35 more

我理解该错误,但是我不知道为什么这种休眠映射在Wildfly中而不在quarkus中起作用?当我声明 jpa字段访问而不是 jpa属性访问时,休眠状态应自动将isArchived()视为transient

或者quarkus是否将所有这些字段注入都编译为属性注入?

1 个答案:

答案 0 :(得分:0)

Quarkus为archived字段生成一个吸气剂。 Hibernate在这里抱怨archived字段有两个访问器:isArchived()getArchived()

这是Hibernate的问题/局限性,与Quarkus无关。

我认为最好是将您的isArchived()方法重命名,因为Hibernate不知道该使用哪种方法来检索archived字段的值。而且,如果您将@Transient添加到isArchived()方法中,则可能(取决于首先获取的夹心方法)将您的字段视为瞬态。