Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
hibernate 3
Mapping:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="hibernateclasses.Artists" table="Artists">
<id name="Id" type="int" column="iArtistId">
<generator class="identity"/>
</id>
<property name="FirstName">
<column name="vFirstName"/>
</property>
<property name="NickName">
<column name="vNickName"/>
</property>
<property name="LastName">
<column name="vLastName"/>
</property>
</class>
</hibernate-mapping>
code:
package hibernateclasses;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class delete {
public static void main(String[] args) {
Session session = null;
Transaction tran;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
String SQL_QUERY = "delete Artists where NickName=?";
tran=session.beginTransaction();
Query q=session.createQuery(SQL_QUERY);
q.setParameter(0,"ee");
int i=q.executeUpate();
//int i=session.createQuery(SQL_QUERY).executeUpate();
tran.commit();
System.out.println(i);
session.close();
}
}
error:
org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:76)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:294)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:808)
at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:89)
at hibernateclasses.delete.main(delete.java:17)
Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'artists0_'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:67)
... 4 more
Exception in thread "main"
my database are using:MSSql2000