entityManager single entity update
jmchiaradia Jun 26, 2009 6:42 PMHello,
I'm new in SEAM (2 month of using this framework).
I have a page that upload files and shows its on a dataGrid where I want to update the each individual file data.
<rich:fileUpload id="file"
fileUploadListener="#{fileUploadBean.persistUploadedFile}"
immediateUpload="true" ajaxSingle="true"
maxFilesQuantity="#{fileUploadBean.fileLeftToUpload}">
<a:support event="onuploadcomplete" reRender="uploadedFiles" />
</rich:fileUpload>
<rich:panel id="uploadedFiles">
<f:facet name="header">
<h:outputText value="Uploaded Files" />
</f:facet>
<h:outputText value="No files currently uploaded"
rendered="#{empty CHIARAfileUploadBean.uploadedFiles}" />
<rich:dataGrid columns="1" value="#{fileUploadBean.uploadedFiles}"
var="_file" rowKeyVar="fileId">
<h:outputText value="File Name:" />
<rich:inplaceInput value="#{_file.name}" />
<h:outputText value="Enabled:"/>
<h:selectBooleanCheckbox value="#{_file.enabledToSend}" />
<h:commandButton action="#{fileUploadBean.updateFile(_file)}" value="Save" />
</rich:dataGrid>
</rich:panel>
The relevant methods on my fileUploadBean are:
public void persistUploadedFile(UploadEvent event) throws Exception{
UploadItem item = event.getUploadItem();
File file = new File();
String[] fullFilename = item.getFileName().split("\\.");
file.setName(fullFilename[0]);
file.setExtension(fullFilename[1]);
file.setMimeType(item.getContentType());
if (item.isTempFile()) {
file.setContent(FileUtils.readFileToByteArray(item.getFile()));
}
else{
file.setContent(item.getData());
}
file.setUploadDate(new Date(System.currentTimeMillis()));
entityManager.persist(file);
uploadedFiles.add(file);
}
public void updateFile(File file){
entityManager.persist(file);
}
The problem is that the file is not updated when I use:
entityManager.persist(file);
If I use:
entityManager.flush()
it works, but the problem with this is that will flush ALL my modified entities and I want to update only the selected file.
Could anyone help me whit this?
Thanks