开发者社区> 问答> 正文

hibernate3.2查询不能用中文做参数?报错

如题,传递参数是中文就报异常

public List<VoteSubject> getSubjectByTitle(String keywords){
		session=super.getSession();
		Query query=session.createQuery("from VoteSubject where vsTitle like :title");
		query.setParameter("title", "%"+keywords+"%");
		return query.list();
	}
	
	public static void main(String[] args)   {
		List<VoteSubject> list=new VoteSubjectDaoImpl().getSubjectByTitle("a");
		for (VoteSubject voteSubject : list) {
			System.out.println(voteSubject.getVsTitle());
		}
	}



这里传递一个英文参数a,hibernate没有报错,正常查询

如果参数传递中文

public static void main(String[] args)   {
		List<VoteSubject> list=new VoteSubjectDaoImpl().getSubjectByTitle("中文");
		for (VoteSubject voteSubject : list) {
			System.out.println(voteSubject.getVsTitle());
		}
	}



这里传递中文参数,发生以下的异常


2014-11-19 21:47:40 org.hibernate.util.JDBCExceptionReporter logExceptions

警告: SQL Error: 1460, SQLState: 72000
2014-11-19 21:47:40 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: ORA-01460: unimplemented or unreasonable conversion requested


Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at dao.impl.VoteSubjectDaoImpl.getSubjectsByTitle(VoteSubjectDaoImpl.java:29)
at dao.impl.VoteSubjectDaoImpl.main(VoteSubjectDaoImpl.java:35)
Caused by: java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested


at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:180)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:419)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:895)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:451)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:985)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2887)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2928)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)

... 7 more


版本是myEClipse里的hibernate3.2版本,求助

展开
收起
爱吃鱼的程序员 2020-06-14 20:06:56 565 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    <divclass="ref">

    引用来自“龚兴耀”的评论

    能把你hibernate.hbm.xml配置文件截图上来看看能把你hibernate.hbm.xml配置文件截图上来看看检查数据连接和数据库使用的字符集<divclass="ref">

    引用来自“JeffreyLin”的评论

    检查数据连接和数据库使用的字符集

    2020-06-14 20:07:11
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载