I was trying to follow the example in the document
http://docs.jboss.org/hibernate/orm/3.3 ... tch-directBut get the following error in my server log:
SEVERE: org.hibernate.QueryException: query must begin with SELECT or FROM: update [update hibernate.TbUser u set u.vcUserName = :userName, u.vcUserPsw = :userPsw, u.vcUserFirstName = :firstName, u.vcUserLastName = :lastName, u.vcUserMiddleName = :middleName, u.vcEmailAddress = :email, u.vcPhoneNumber = :phone, u.dtTerminatedDate = :termDate, u.dtHireDate = :hireDate, u.dtUpdTime = :updTime, u.iUpdUserId = :userId where iUserId = :id]
This suggests I need to start the query with SELECT or FROM, however the example uses "Update" in the update query, so I do not understand what the problem is.
Can anyone show me to an example of how to do an Update???
The documentation apparently does not.
Thanks.
Here is the code I am trying to execute:
Code:
public int updateUser( String userName, String passwd, String firstName, String middleName,
String lastName, String email, String phone, Date termDate, Date hireDate, int id )
{
int status = 0;
try
{
org.hibernate.Transaction tx = session.beginTransaction();
String cmd = "update TbUser u set u.vcUserName = :userName, "+
"u.vcUserPsw = :userPsw, u.vcUserFirstName = :firstName, "+
"u.vcUserLastName = :lastName, u.vcUserMiddleName = :middleName, "+
"u.vcEmailAddress = :email, u.vcPhoneNumber = :phone, "+
"u.dtTerminatedDate = :termDate, u.dtHireDate = :hireDate, "+
"u.dtUpdTime = :updTime, u.iUpdUserId = :userId where iUserId = :id";
Query q = session.createQuery( cmd );
q.setString("userName", userName);
q.setString("userPsw", passwd);
q.setString("firstName", firstName);
q.setString("middleName", middleName);
q.setString("lastName", lastName);
q.setString("email", email);
q.setString("phone", phone);
q.setDate("termDate", termDate);
q.setDate("hireDate", hireDate);
q.setDate("updTime", new Date());
q.setInteger("id", id);
status = q.executeUpdate();
tx.commit();
}
catch( Exception e )
{
e.printStackTrace();
status = -1;
}
return status;
}