与hibernate和spring social一起工作,
我正在尝试通过电子邮件地址查询数据库。当我做这个查询时:
公共帐户 findAccountByUsername(String username) {
Session session = sessionFactory.getCurrentSession(); String selectQuery = "FROM Account as account WHERE account.username = "+username; Query query = session.createQuery(selectQuery); @SuppressWarnings("unchecked") List<Account> results = query.list(); if (!results.iterator().hasNext()) return null; return results.iterator().next(); }
我得到了这个例外
2013-01-22 14:37:13,090 [调试] [HibernateTransactionManager,doBegin(),569] - 将 Hibernate 事务公开为 JDBC 事务 [com.mchange.v2.c3p0.impl.NewProxyConnection@3b249bb2] 2013-01-22 14 :37:13,352 [DEBUG] [QueryTranslatorImpl,parse(),272] - parse() - HQL: FROM masterPackage.model.orm.Account as account WHERE account.username = myEmail@gmail.com 2013-01-22 14: 37:13,383 [DEBUG] [AbstractPlatformTransactionManager,processRollback(),843] - 启动事务回滚 2013-01-22 14:37:13,384 [DEBUG] [HibernateTransactionManager,doRollback(),672] - 在会话 [org] 上回滚 Hibernate 事务.hibernate.impl.SessionImpl@294a7134] 2013-01-22 14:37:13,385 [调试] [JDBCTransaction,rollback(),186] - 回滚
…………
2013-01-22 14:37:18,818 [WARN] [ProviderSignInController,oauth2Callback(),177] - 处理 OAuth2 回调时出现异常(意外字符:'@' [FROM masterpackage.model.orm.Account as account WHERE account.username = myEmail@gmail.com])。重定向到 /signin
有没有办法解决这个问题?
总有一种方法可以将电子邮件地址中的 @ 字符另存为其他字符,但我想问是否有比这个解决方案更好的方法。