I m not very versed in Hibernate and have following query:
Consider two classes:
public class Ticket{
private List<Attachement> attachmentList=new ArrayList<Attachment>();
...
}
public class Attachment{
private String fileName;
private bytes[] fileData;
}
consider a scenario:
user opens a ticket to see its details.Along with ticket details list of all attachements related to that ticket will also shown up(i mean only names of attachments). user will click on a filename to download that attachment.
While displaying details of ticket I do not want to fetch the related attachments data until user click on their fienames to download them. (I want to show their names only)
With lazy loading, loading of attachements can be deferred but how to fetch their filenames (‘fileName‘ attribute of class Attachment) earlier only but not the ‘fileData‘.
Thanks in advance.
You need to write a custom query to load just the names of the attachments. In your application, you should have some sort of
TicketServicewith aloadTicketmethod on it. In that method, you should load the ticket (and only the ticket), and then just the names of the Attachments that are attached to the ticket.Return that data to the UI. When the user clicks an attachment name, you can then load the full Attachment.