I'm trying to improve the performance of a project that uses JPA.
I'm using JPA 2.1 and Hibernate 5.0.1 implementation.
I changed the FetchType of a ManyToOne relation to Lazy, so the thing blows up.
When I just try to lookup all the records of the child object: the last record come with all empty fields and with a handler=JavassistLazyInitializer. And this strange behaviour impacts on the fields that use this objects (Like h:OneSelectMenu).
If I remove the FetchType.Lazy the thing back normal.
Some prints:
Code of the second print (FetchType.Lazy):
public class Usuario implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id_Usuario")
private Integer idUsuario;
// Fields ...
@JoinColumn(name = "Id_Tipo_Logradouro", referencedColumnName = "Id_Tipo_Logradouro", nullable = true)
@ManyToOne(optional = true, fetch = FetchType.LAZY)
private TipoLogradouro tipoLogradouro;
@JoinColumn(name = "Id_Tipo_Usuario", referencedColumnName = "Id_Tipo_Usuario")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private TipoUsuario tipoUsuario;
@JoinColumn(name = "Id_Supervisor", referencedColumnName = "Id_Usuario")
@ManyToOne(optional = true, fetch = FetchType.LAZY)
private Usuario supervisor;
// Contructor, Getters Setters etc ...
}
public class TipoUsuario implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 1)
@Column(name = "Id_Tipo_Usuario")
private String idTipoUsuario;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 20)
@Column(name = "Descricao")
private String descricao;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 1)
@Column(name = "Possui_Supervisor")
private String possuiSupervisor;
@Size(max = 1)
@Column(name = "Possui_Meta")
private String possuiMeta;
@Size(max = 1)
@Column(name = "Recebe_Alerta")
private String recebeAlerta;
@Transient
private List<Usuario> usuarioList = new ArrayList<>();
//Contructor, Getters Setters etc ...