@PostLoad带注释的方法不会在实体

时间:2016-09-08 18:44:25

标签: java hibernate jpa

我试图找出为什么在从数据库加载对象后永远不会调用@PostLoad带注释的方法:

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "key.job", targetEntity = ScheduledJobParam.class, orphanRemoval = true)
@XmlTransient
private Set<ScheduledJobParam> paramSet;

@Transient
private Map<String, ScheduledJobParam> params;

@PostLoad
public void indexParameters() {

    this.params = new HashMap<>();

    for(ScheduledJobParam param : this.paramSet) {

        String paramName = param.getKey().getName();
        this.params.put(paramName, param);
    }
}

我需要它的原因是因为子行被加载到Set中,但我想将它们放在Map中,以便通过键轻松检索:

public String getParameterValue(String _paramName) {
    String result = null;
    ScheduledJobParam param = this.params.get(_paramName);

    if(param != null) {
        result = param.getValue();
    }

    return result;
}

我的JPA提供商是Hibernate

0 个答案:

没有答案