I'm having a strange problem. I have been using Hibernate in a webapp with no problems. Now I have to write a stand-alone utility using Hibernate. The problem is that when I try to save an object using the way I'm used to, with session.flush(), it isn't saving. But if I put everything inside a transaction it does. The only difference between this setup and the webapp is in the webapp we use a connection pool.
Thanks,
Karl
Hibernate version: 3.0.5
Code between sessionFactory.openSession() and session.close(): session = HibernateFactory.currentSession(); sql = "select dtype from DocumentType dtype where dtype.department.departmentName = ? and dtype.docTypeName = ?"; Query query = session.createQuery(sql); query.setString(0, edi.props.getProperty("department")); query.setString(1, edi.props.getProperty(propDocType + "DocType")); DocumentType docType = (DocumentType) query.uniqueResult(); Batch batch = new Batch(); batch.setId(new Long(0)); batch.setDocTypeNo(docType.getDocTypeNo()); batch.setScannerBatch("EDIUPLOAD"); batch.setScanDate(date.getTime()); batch.setImportDate(date.getTime()); // SAVE THE BATCH SO WE CAN GET THE NEW BATCH ID. IT IS NEEDED TO BUILD THE UPLOAD PATH batch = (Batch)session.merge(batch); System.out.println(batch.getBatchNo()); session.flush();
Full stack trace of any exception that occurs: none
Name and version of the database you are using: SQL Server 2000
The generated SQL (show_sql=true): Hibernate: insert into BATCH (BATCH_SCANERBATCH, BATCH_SCANDATE, BATCH_IMPORTDATE, DOCUMENTTYPE_NO) values (?, ?, ?, ?) select scope_identity()
|