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

Success1024 发布于 2014/11/19 21:59
阅读 723
收藏 0

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

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版本,求助

加载中
0
S
Success1024

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

能把你hibernate.hbm.xml配置文件截图上来看看
这是配置截图,谢谢关注
0
龚兴耀
龚兴耀
能把你hibernate.hbm.xml配置文件截图上来看看
0
JeffreyLin
JeffreyLin
检查数据连接和数据库使用的字符集
0
S
Success1024

引用来自“JeffreyLin”的评论

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

SQL*PLUS 中,以DBA登录

conn 用户名 as sysdba

然后执行以下命令

 

>shutdown immediate; (database停了)

>startup mount; (database重开去可更改情況)

>alter system enable restricted session;

>alter system set job_queue_processes=0;

>alter system set aq_tm_processes=0;

>alter database open;

>alter database character set utf8;

OR

>alter database character set internal_use utf8;

>shutdown immediate;

>startup; (重开正常oracle)


谢谢提醒,我把数据库字符集设置成了UTF-8然后重新录入数据查到了

返回顶部
顶部