简体   繁体   English

带有查询的org.springframework.orm.hibernate4.HibernateQueryException(Spring mvc)

[英]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.

相关问题 org.springframework.orm.hibernate4.HibernateQueryException:DML操作不支持[更新] - org.springframework.orm.hibernate4.HibernateQueryException: Not supported for DML operations [UPDATE] Spring 4 + Hibernate 5 = org.springframework.orm.jpa.EntityManagerHolder无法转换为org.springframework.orm.hibernate5.SessionHolder - Spring 4 + Hibernate 5 = org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean - org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean Spring 3 + Hibernate 4 + C3P0:java.lang.NoSuchMethodError:org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass - Spring 3 + Hibernate 4 + C3P0: java.lang.NoSuchMethodError: org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.addAnnotatedClass Java、Spring、Hibernate 找不到 org.springframework.orm.hibernate3.LocalSessionFactoryBean - Java, Spring, Hibernate cannot find org.springframework.orm.hibernate3.LocalSessionFactoryBean org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException - org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException spring hibernate 5 Error已经值[org.springframework.orm.hibernate5.SessionHolder用于键绑定到线程 - spring hibernate 5 Error Already value [org.springframework.orm.hibernate5.SessionHolder for key bound to thread spring 迁移 4 到 5; 是什么导致 java.lang.ClassNotFoundException:org.springframework.orm.hibernate4.LocalSessionFactoryBean - spring migration 4 to 5; what is causing java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean 在 spring 中获取 org.springframework.orm.ObjectOptimisticLockingFailureException - Getting org.springframework.orm.ObjectOptimisticLockingFailureException in spring org.springframework.orm.hibernate3.HibernateTemplate是纯休眠还是JPA实现? - org.springframework.orm.hibernate3.HibernateTemplate is pure hibernate or JPA implemenation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM