我正在尝试强制 HQL 急切加载所有 Lazy 属性。使用 FETCH 给了我“多袋”异常,我无法将其更改为 Set,因为它们在其他地方被引用。我尝试了其他映射注释,但没有运气。“FETCH ALL PROPERTIES”被忽略,没有加载任何内容。我一直不明白它的真正作用。显然,当 JSF 尝试读取列表时,我得到“无法初始化惰性列表。连接关闭”
我正在使用休眠 4.0。所以这是我的 HQL 查询:
Select r from Responsavel r FETCH ALL PROPERTIES
where r.unidadeEmpresarial.id = :idUnidade
这是我的模型课:
public class Responsavel {
@Id
@SequenceGenerator(name = "SQ_RESPONSAVEL_GENERATOR", sequenceName = "SE_RESPONSAVEL", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SQ_RESPONSAVEL_GENERATOR")
@Column(name = "SQ_RESPONSAVEL")
private Long id;
@Temporal(TemporalType.DATE)
@Column(name = "DT_FIM")
private Date dataFim;
@NotNull
@Temporal(TemporalType.DATE)
@Column(name = "DT_INICIO")
private Date dataInicio;
@Temporal(TemporalType.DATE)
@Column(name = "DT_NASCIMENTO")
private Date dataNascimento;
@Type(type = "org.hibernate.type.NumericBooleanType")
@Column(name = "IN_PODER_ADM_REPRES")
private Boolean temPoderAdministrativo;
@Column(name = "NO_RESPONSAVEL")
private String nome;
@Column(name = "NU_CPF_CNPJ_RESPONSAVEL")
private String numeroCpfCnpj;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "TP_PESSOA")
private String tipoPessoa;
@ManyToOne
@JoinColumn(name = "SQ_PAIS")
private Pais pais;
@Column(name = "VL_CAPITAL_SOCIAL")
private BigDecimal valorCapitalSocial;
@Column(name = "PC_CAPITAL_SOCIAL")
private BigDecimal percentualCapitalSocial;
@ManyToOne
@JoinColumn(name = "SQ_UNIDADE_EMPRESARIAL")
private UnidadeEmpresarial unidadeEmpresarial;
@OneToMany(mappedBy = "responsavel", fetch = FetchType.LAZY)
@Fetch(FetchMode.SUBSELECT)
private Set<ResponsavelQualificacaoResponsavel> listaResponsavelQualificacaoResponsavel;
@OneToMany(mappedBy = "responsavel")
private List<Representante> representantes;
@OneToMany(mappedBy = "responsavel")
private List<ContatoResponsavel> contatoResponsavel;
@OneToMany(mappedBy = "responsavel", cascade = CascadeType.ALL)
private List<EnderecoResponsavel> enderecoResponsavel;
}
谢谢