我无法在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时,我得到了延迟初始化异常。我无法理解为什么会这样。有人可以帮忙吗?