hibernate不急切地加载@any assosciations

时间:2018-01-08 19:17:57

标签: hibernate jpa

我无法在hibernate中急切地加载多态关联对象。我知道默认的FetchType是@Any的渴望,但我不能急切地加载字段。这是一段代码:

@Entity
public class ActionTemplate {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Any(metaColumn = @Column(name ="protocol_type"),fetch = 
FetchType.EAGER)
@AnyMetaDef(idType = "long",metaType = "string",metaValues = {@MetaValue(targetEntity = Http.class,value = "http")})
@JoinColumn(name = "protocol_id")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
private ActionProtocol protocol;
}

public interface ActionProtocol {
ProtocolType getType();
}


@Entity
public class Http implements ActionProtocol{
            //some data fields and methods
}

当我从hibernate获取id时,我得到了延迟初始化异常。我无法理解为什么会这样。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这是Hibernate中已存在10年的错误。 https://hibernate.atlassian.net/browse/HHH-3574