I have a issue with loading data about object mapped.
I have 2 entities classes.
The first :
@Entity
@Table(name = "DOCUMENT")
public class Document implements java.io.Serializable {
private static final long serialVersionUID = -5160452300417105888L;
private Long idDocument;
private Dossier dossier;
private DocumentStatut documentStatut;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "Document_seq_gen")
@SequenceGenerator(name = "Document_seq_gen", sequenceName = "SEQUENCE_DOCUMENT")
@Column(name = "ID_DOCUMENT", unique = true, nullable = false, precision = 10, scale = 0)
public Long getIdDocument() {
return this.idDocument;
}
public void setIdDocument(final Long idDocument) {
this.idDocument = idDocument;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_DOSSIER", nullable = false)
public Dossier getDossier() {
return this.dossier;
}
public void setDossier(final Dossier dossier) {
this.dossier = dossier;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_STATUT", nullable = false)
public DocumentStatut getDocumentStatut() {
return this.documentStatut;
}
public void setDocumentStatut(final DocumentStatut documentStatut) {
this.DocumentStatut = documentStatut;
}
}
The second,
@Entity
@Table(name = "DOCUMENT_STATUT")
public class DocumentStatut implements java.io.Serializable {
private Long idStatut;
private String libStatut;
@Id
@Column(name = "ID_STATUT", unique = true, nullable = false, precision = 10, scale = 0)
public Long getIdStatut() {
return this.idStatut;
}
public void setIdStatut(final Long idStatut) {
this.idStatut = idStatut;
}
@Column(name = "LIB_STATUT", length = 30)
public String getLibStatut() {
return this.libStatut;
}
public void setLibStatut(final String libStatut) {
this.libStatut = libStatut;
}
}
I get Document data using org.hibernate.Criteria
For each Document instance, the field documentStatut has only his idStatut setted. I think it is normal because of lazy property.
But, when I call doument.getDocumentStatut(), I wish a sql select is executed for getting the others fields od DocumentStatut. But not, no query is launched and I have to "manually" execute a select query for getting a complete instance of DocumentStatut.
I use : - hibernate 3.3.2.GA - Websphere 8.5 - Spring 3.2.6.RELEASE - Java 7