-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Not Saving
PostPosted: Thu Oct 27, 2005 4:20 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 4:59 pm
Posts: 23
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()


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 4:27 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
Since you can see that Hibernate is issuing the insert for your new row but then afterwards you can't find it perhaps some how a rollback is getting issued. Perhaps you should retreive the JDBC connection immediately after the flush and issue a commit. If that fixes things then you know what you need to find out is why a rollback is being issued.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.