I'm having some trouble getting an attribute on an entity to lazy load. I've scoured the EclipseLink documentation but can't figure out what I'm doing wrong.
Basically, I have a table with some columns, one of which is a file, the size of which can be very large. I'd like to have the file itself lazy load, so that when I load all the rows of the table I don't have to wait for the file to load into memory if it won't be used.
The setup:
EclipseLink 2.6.2
ReportHistoryFile:
@Entity
@Table(name = "REPORT_HISTORY_FILES")
@NamedQueries({
@NamedQuery(name = "ReportHistoryFile.findAll", query = "SELECT p FROM ReportHistoryFile p order by p.createDate DESC")})
public class ReportHistoryFile implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "SEQ_REPORTHISTORYFILE_GEN", sequenceName = "SEQ_REPORTHISTORYFILE", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_REPORTHISTORYFILE_GEN")
private Long fileId;
// note the basic lazy setting
@Basic(fetch = FetchType.LAZY)
@Column(name = "FILE_CONTENT", nullable = false)
private byte[] fileContent;
@Column(name = "FILE_NAME", nullable = false)
private String fileName;
private String contentType;
@Column(name = "FILE_SIZE")
private Long fileSize;
@Column(name = "CREATEDATE")
private Date createDate;
public ReportHistoryFile() {
}
public Long getFileId() {
return fileId;
}
public void setFileId(Long fileId) {
this.fileId = fileId;
}
public byte[] getFileContent() {
if (fileContent == null) {
return null;
}
return Arrays.copyOf(fileContent, fileContent.length);
}
public void setFileContent(byte[] fileContentIn) {
if (fileContentIn != null) {
this.fileContent = Arrays.copyOf(fileContentIn, fileContentIn.length);
}
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getCreateDate() {
return this.createDate;
}
}
But when I execute this code (em
is the EntityManager):
List<ReportHistoryFile> list = null;
try {
list = (List<ReportHistoryFile>) em.createNamedQuery("ReportHistoryFile.findAll")
.getResultList();
} catch (javax.persistence.NoResultException e) {
log.info("No Report History File records found.");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
I see this printed out to the console:
[EL Fine]: sql: 2017-01-25 10:35:44.223--ServerSession(1159663071)--Connection(39105078)--SELECT FILEID, CONTENTTYPE, CREATEDATE, FILE_CONTENT, FILE_NAME, FILE_SIZE FROM REPORT_HISTORY_FILES ORDER BY CREATEDATE DESC
Notice that FILE_CONTENT is still in the statement. What am I missing? I don't think I need anything special in my persistence.xml file for just the basic lazy load, but I could be wrong. Thanks in advance!