[英]org.springframework.orm.hibernate4.HibernateQueryException with Query (Spring mvc)
I have got a Query. 我有一个查询。 (It's my full DAO method) (这是我完整的DAO方法)
@Override
public void addUserRole(UserRole userRole) {
Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
String query = "insert into 'user_roles'('role','username') values(%s,%s)";
Session session = this.sessionFactory.getCurrentSession();
List roleAdd = session.createQuery(String.format(query, "'ROLE_USER'", "'acid'")).list();
tx.commit();
}
And it gives me an exception 这给了我一个例外
type Exception report message Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateQueryException: expecting IDENT, found ''user_roles'' near line 1, column 13
[insert into 'user_roles'('role','username') values('ROLE_USER','acid')]; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: expecting IDENT, found ''user_roles'' near line 1, column 13
[insert into 'user_roles'('role','username') values('ROLE_USER','acid')] description The server encountered an internal error that prevented it from fulfilling this request.
Here's what your method should look like: 这是您的方法应为:
@Override
public void addUserRole(UserRole userRole) {
Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
String query = "insert into 'user_roles'('role','username') values(%s,%s)";
Session session = this.sessionFactory.getCurrentSession();
int resultCount = session.createSQLQuery(String.format(query, "'ROLE_USER'", "'acid'")).executeUpdate();
tx.commit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.