Hi there,
I'm on SmartGWT EE 4.0d, nightly 2013-05-20.
This is mi issue: I've got a databound ListGrid and a DynamicForm (bind to same datasource as ListGrid) which perform the file upload to database. At the end of DynamicForm.saveData(...) execution (upload process), I obtain the exceptions in attach (marked with _UPLOAD) and after that, when ListGrid attempt to perform a "fetch" operation, no data were loading. In attachment the exceptions (markerd with _FETCH) I got.
Database record are inserted succesfully (checked by pgAdminIII).
Here some of my code:
DocumentDAO.java (DMI implementation based on Spring):
Form source:
Client datasource definition:
Server (.ds.xml) datasource definition:
Hibernate entity:
and the Postgresql table definition (binary file going into bytea column):
Any suggestion?
Thanks, Luca.
I'm on SmartGWT EE 4.0d, nightly 2013-05-20.
This is mi issue: I've got a databound ListGrid and a DynamicForm (bind to same datasource as ListGrid) which perform the file upload to database. At the end of DynamicForm.saveData(...) execution (upload process), I obtain the exceptions in attach (marked with _UPLOAD) and after that, when ListGrid attempt to perform a "fetch" operation, no data were loading. In attachment the exceptions (markerd with _FETCH) I got.
Database record are inserted succesfully (checked by pgAdminIII).
Here some of my code:
DocumentDAO.java (DMI implementation based on Spring):
Code:
@Repository("documentDao")
public class DocumentDao {
Logger log = new Logger(DocumentDao.class.getName());
@Autowired
private SessionFactory sessionFactory;
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public DSResponse fetch(DSRequest dsRequest) throws Exception {
DSResponse dsResponse = new DSResponse();
Session hibernateSession = sessionFactory.getCurrentSession();
List<Document> docList = hibernateSession.getNamedQuery("Document.fetchAll").list();
log.info("FETCH " + docList.size() + " kiosk record");
dsResponse.setData(docList);
return dsResponse;
}
@Transactional(propagation = Propagation.REQUIRED)
public DSResponse add(DSRequest dsRequest, Document item) throws Exception {
DSResponse dsResponse = new DSResponse();
Session session = sessionFactory.getCurrentSession();
item.setFileName(item.getFile().getName());
item.setUploadDate(new Date(System.currentTimeMillis()));
System.out.println("TEST_SIZE:" + item.getFile().length());
session.saveOrUpdate(item);
log.info("ADD new document " + item.getFileName() + " record");
dsResponse.setData(item);
return dsResponse;
}
[...other CRUD metod...]
Code:
public class DocumentEditForm extends DynamicForm {
private ListGrid referredGrid = null;
private Criteria referredGridCurrCriteria = null;
private final int WIDTH = 400;
private final int HEIGHT = 300;
private FileItem fileItem = null;
private TextAreaItem notesItem = null;
public DocumentEditForm(ListGrid referredGrid) {
this.referredGrid = referredGrid;
this.referredGridCurrCriteria = referredGrid.getCriteria();
setDataSource(this.referredGrid.getDataSource());
setWidth(WIDTH);
setHeight(HEIGHT);
setMargin(5);
setCellPadding(5);
setAutoFocus(true);
setUseAllDataSourceFields(false);
initComponents();
}
private void initComponents() {
fileItem = new FileItem(DocumentDSFields.FILE.getAlias());
fileItem.setColSpan(2);
fileItem.setWidth("100%");
fileItem.setTitleOrientation(TitleOrientation.TOP);
notesItem = new TextAreaItem(DocumentDSFields.NOTES.getAlias());
notesItem.setColSpan(2);
notesItem.setWidth("100%");
notesItem.setTitleOrientation(TitleOrientation.TOP);
notesItem.setLength(2048);
ButtonItem saveBtn = new ButtonItem("saveBtn", "Add");
saveBtn.setWidth(60);
saveBtn.setColSpan(2);
saveBtn.setIcon("[SKIN]/actions/add.png");
saveBtn.setAlign(Alignment.CENTER);
saveBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (validate()) {
saveData(new DSCallback() {
@Override
public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
resetValues();
referredGrid.filterData(referredGridCurrCriteria);
}
});
}
}
});
this.setFields(fileItem, notesItem, new SpacerItem(), saveBtn);
}
}
Code:
public class DocumentDS extends DataSource {
private DataSourceField id = null;
private DataSourceField filename = null;
private DataSourceField uploadDate = null;
private DataSourceField notes = null;
private DataSourceField file = null;
/**
* Default constructor
*/
public DocumentDS(String dsAlias) {
setID(dsAlias);
id = new DataSourceField(DocumentDSFields.ID.getAlias(), FieldType.SEQUENCE);
id.setPrimaryKey(true);
id.setRequired(true);
id.setHidden(true);
filename = new DataSourceField(DocumentDSFields.FILENAME.getAlias(), FieldType.TEXT);
filename.setTitle(I18n.CST.documentFilenameLbl());
uploadDate = new DataSourceField(DocumentDSFields.UPLOAD_DATE.getAlias(), FieldType.DATETIME);
uploadDate.setTitle(I18n.CST.docuemtnUploadDateLbl());
notes = new DataSourceField(DocumentDSFields.NOTES.getAlias(), FieldType.TEXT);
notes.setTitle(I18n.CST.docuemtnNotesLbl());
notes.setLength(2048);
file = new DataSourceField(DocumentDSFields.FILE.getAlias(), FieldType.BINARY);
setFields(id, filename, uploadDate, notes, file);
}
}
Code:
<DataSource ID="dpDocument" schemaBean="it.onetech.dtproviding.server.entity.Document"> <serverObject lookupStyle="spring" bean="documentDao" /> </DataSource>
Code:
@Entity
@Table(name = "document")
@NamedQueries({
@NamedQuery(name = "Document.fetchAll", query = "from Document order by fileName")
})
public class Document implements Serializable {
private static final long serialVersionUID = 1182313769904090209L;
@Id
@SequenceGenerator(name = "idSeq", sequenceName = "document_id_seq")
@GeneratedValue(generator = "idSeq")
protected Long id = null;
@Column(name = "filename")
protected String fileName = null;
@Column(name = "upload_gmt")
protected Date uploadDate = null;
@Column(name = "add_info")
protected String notes = null;
@Column(name = "file")
protected File file = null;
[...getter and setter...]
Code:
CREATE TABLE dtproviding.document ( id bigserial NOT NULL, filename character varying(255), upload_gmt timestamp without time zone, add_info character varying(2048), file bytea, CONSTRAINT document_pkey PRIMARY KEY (id) )
Thanks, Luca.
Comment