public AttachmentFile addAttachmentFile(AttachmentFile attachmentFile) {
??try {
???attachmentFile.setAttachmentFileBlob(BLOB.empty_lob());
??} catch (SQLException e) {
???e.printStackTrace();
??}
??AttachmentFile savedAttachmentFile = (AttachmentFile)super.saveObject(attachmentFile);
??getHibernateSession().flush();
??return (AttachmentFile) updateAttachmentFileBlob(savedAttachmentFile);
?}
public AttachmentFile updateAttachmentFileBlob(AttachmentFile attachmentFile) {
??//Connection jdbcConnection = this.getHibernateSession().connection();
??
??if (attachmentFile.getAttachmentFile() != null){
???
???getHibernateSession().refresh(attachmentFile, LockMode.UPGRADE);
???Blob sqlBlob = attachmentFile.getAttachmentFileBlob();
???org.hibernate.lob.SerializableBlob hbmBlob = (org.hibernate.lob.SerializableBlob)sqlBlob;
???BLOB oracleBlob = (BLOB)hbmBlob.getWrappedBlob();
???OutputStream os;
???try {
????os = oracleBlob.getBinaryOutputStream();
????os.write(attachmentFile.getAttachmentFile());
????os.close();
???} catch (Exception e1) {
????throw new? SystemRuntimeException(e1.getMessage(),e1);
???}
??}
對了Blob和Clob,需要先save一個空的Blob(Clob),然后,在update.
??try {
???attachmentFile.setAttachmentFileBlob(BLOB.empty_lob());
??} catch (SQLException e) {
???e.printStackTrace();
??}
??AttachmentFile savedAttachmentFile = (AttachmentFile)super.saveObject(attachmentFile);
??getHibernateSession().flush();
??return (AttachmentFile) updateAttachmentFileBlob(savedAttachmentFile);
?}
public AttachmentFile updateAttachmentFileBlob(AttachmentFile attachmentFile) {
??//Connection jdbcConnection = this.getHibernateSession().connection();
??
??if (attachmentFile.getAttachmentFile() != null){
???
???getHibernateSession().refresh(attachmentFile, LockMode.UPGRADE);
???Blob sqlBlob = attachmentFile.getAttachmentFileBlob();
???org.hibernate.lob.SerializableBlob hbmBlob = (org.hibernate.lob.SerializableBlob)sqlBlob;
???BLOB oracleBlob = (BLOB)hbmBlob.getWrappedBlob();
???OutputStream os;
???try {
????os = oracleBlob.getBinaryOutputStream();
????os.write(attachmentFile.getAttachmentFile());
????os.close();
???} catch (Exception e1) {
????throw new? SystemRuntimeException(e1.getMessage(),e1);
???}
??}
對了Blob和Clob,需要先save一個空的Blob(Clob),然后,在update.