Ajuda Com FetchType.LAZY

0 respostas
T

Bom dia a todos.

Gostaria de ajuda dos colegas, estou tentando carregar uma tabela de contatos, que pertence ao cadastro de pacientes.
A idéia seria na view ter duas abas (Paciente) e (Contatos), ao clicar na aba contatos carregar os contatos com LAZY.

Segue a classe model..

@Entity
@Table(name="Paciente")
public class Paciente implements Serializable{
	
	private static final long serialVersionUID = 7676073211709319516L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long cod_paciente;
	
	@Column(length=100, nullable=false )
	private String nom_paciente;
	
	@OneToMany(targetEntity=ContatoPaciente.class, mappedBy="paciente")
        private List<ContatoPaciente> contatos;
      
        //........... GET / SETS E HASH CODE ......
@Entity
@Table(name="ContatoPaciente")
@NamedQuery(name="ContatoPaciente",query ="from ContatoPaciente")
public class ContatoPaciente implements Serializable{
	
	private static final long serialVersionUID = -8163509704522217571L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long cod_contato;
	
	@ManyToOne(cascade= CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinColumn(name="cod_paciente", nullable = false)
	private Paciente paciente;
	
	@Column(length=100, nullable=false )
	private String nom_contato;
	
	@Column(length=45, nullable=false )
	private String tel_contato;
      //........... GET / SETS E HASH CODE ......
Ao chamar na view o get de List<ContatoPaciente> não deveria carregar automaticamente os contatos? Estou utilizando JSF 2.0 com hibernate e primefaces. Desde já agradeço.
Criado 17 de agosto de 2011
Respostas 0
Participantes 1