Re: Hibernate305: delete query fails with "must begin with SELECT or FROM"
hi-
i use hibernate and the newsgroup over their had some sort of merit system.
i dont have much merit to offer but here is some code from my program
i am working on that might help you see what you did wrong.
this delete query works.
hope it helps,
jim
private void deleteRecord(){
IStructuredSelection selection =
(IStructuredSelection)tableViewer.getSelection();
Register register = (Register)selection.getFirstElement();
if (register == null) {
System.out.println("Please select an item first. ");
return;
}
MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO);
messageBox.setText("Confirmation");
messageBox.setMessage(
"Are you sure to remove the bug with id #"
+ register.transactionid);
if (messageBox.open() == SWT.YES) {
//register.remove(register);
Session session =
HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Query query = session.createQuery("delete from Transact where transactionid
= ?");
query.setLong(0, Long.valueOf(register.transactionid));
int count = query.executeUpdate();
tx.commit();
session.flush();
bugs.remove(table.getSelectionIndex());
tableViewer.setInput(bugs);
tableViewer.refresh();
} catch (HibernateException e) {
if (tx != null) tx.rollback();
displayErrorMsg(e);
} catch(Exception e1){
System.out.println("Error: " + e1.getMessage());
displayErrorMsg(e1);
}finally {
session.close();
}
}
}