全局注册DynamicParameterizedType

时间:2020-08-24 16:03:24

标签: spring-boot hibernate jpa

如何在休眠状态下注册全局可用的{% for menu in menus %}

我写了以下类型:

DynamicParameterizedType

并在休眠中向服务注册进行注册:

public class QuantityType extends AbstractSingleColumnStandardBasicType<Quantity<?>> implements DynamicParameterizedType {

    public static final QuantityType INSTANCE = new QuantityType();

    public QuantityType() {
        super(DoubleTypeDescriptor.INSTANCE, new QuantityJavaDescriptor(AbstractUnit.ONE));
    }

    @Override
    public String getName() {
        return QuantityType.class.getSimpleName();
    }

    @Override
    public void setParameterValues(Properties parameters) {
        ParameterType reader = (ParameterType) parameters.get(PARAMETER_TYPE);
        if (reader == null) throw new RuntimeException("Not Implemented");
        Unit<?> resolvedUnit = resolveUnit(reader);
        setJavaTypeDescriptor(new QuantityJavaDescriptor(resolvedUnit));
    }

    private Unit<?> resolveUnit(ParameterType reader) {...}
}

如果我在实体中使用该类型,则会调用JavaTypeDescriptor的wrap / unwrap方法, 但是会调用默认的JavaTypeDescriptor而不是参数化的JavaTypeDescriptor。由于某些原因,未调用public class QuantityTypeRegistration implements TypeContributor { @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { typeContributions.contributeType(QuantityType.INSTANCE); } } 方法。

代码:https://github.com/raynigon/unit-api/tree/master/jpa-starter/src/main/java/com/raynigon/unit_api/jpa

0 个答案:

没有答案
相关问题