I am pretty new in JPA and Hibernate and I have the following problem.
Into a Spring MVC project I have this Tid001Anagpartecipa model class that map the fields on the TID001_ANAGPARTECIPA table defined on the database:
@Entity
@Table(name="TID001_ANAGPARTECIPA")
@NamedQuery(name="Tid001Anagpartecipa.findAll", query="SELECT t FROM Tid001Anagpartecipa t")
public class Tid001Anagpartecipa implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="PRG_PAR")
private Integer prgPar;
................................................................
................................................................
................................................................
@Lob @Basic(fetch=FetchType.LAZY)
@Column(name="OGG_DOC_ALL")
private byte[] oggDocAll;
@Lob @Basic(fetch=FetchType.LAZY)
@Column(name="OGG_DOC_DEL_ALL")
private byte[] oggDocDelAll;
................................................................
................................................................
GETTER & SETTER METHODS
................................................................
................................................................
}
As you can see on this table there are 2 BLOB fields annoted with the @Lob annotation, these fields contain 2 files stored on the DB.
In this class is also declared this named query that retrieve all the Tid001Anagpartecipa object stored as record of the TID001_ANAGPARTECIPA table:
As you can see in the previous code snipper the @Lob fields it used the lazy strategy (by @Basic(fetch=FetchType.LAZY)). So I expected that when I retrieve a Tid001Anagpartecipa object these 2 @Lob fields are not initizialized.
Into a controller method I perform this operation that retrieve the Tid001Anagpartecipa object:
Tid001Anagpartecipa anagrafica = getAnagraficaPartecipante(model);
List<Tid002Candidatura> listaCandidatureDB = anagrafica.getTid002Candidaturas();
The object is correctly retrieve but the problem is that the previous 2 @Lob fields are inizialized and I want that these fields are not inizialized (infact I used the @Basic(fetch=FetchType.LAZY) directive).
Why are these fields retrieved? What am I missing? How can I say to Hibernate to not retrieve these @Lob fields when the Tid001Anagpartecipa is retrieved?
Tnx