Hibernate查询错误!请高手帮忙解决!

 

 源代码:

 public List findByBianhao(String bianhao) {
  Transaction tx = null;
  List list = null;
  try {
   session = hib.openSession();
   tx = (Transaction) session.beginTransaction();
   Query query = session
     .createQuery("from Lipin where bianhao =:bianhao");
   query.setString("bianhao",bianhao);
      list = query.list();
   tx.commit();
   hib.closeSession(session);
  } catch (Exception e) {
      e.printStackTrace();
      tx.rollback();
  }
  return list;
 }

 

实体类名为:Lipin       表名为:lipin1

我用的mysql数据库是5.0的,hibernate是3.2 的!

执行完查询语句之后出现这样的问题:

 

Hibernate: select lipin0_.id as id0_, lipin0_.name as name0_, lipin0_.Vip_jiage as Vip3_0_, lipin0_.Shichang_jiage as Shichang4_0_, lipin0_.Huiyuan_jiage as Huiyuan5_0_, lipin0_.bianhao as bianhao0_, lipin0_.caizhi as caizhi0_, lipin0_.guige as guige0_, lipin0_.peisongfanwei as peisongf9_0_, lipin0_.huayu as huayu0_, lipin0_.picture as picture0_ from lipin1 lipin0_ where lipin0_.bianhao=?
12:00:23,265  WARN JDBCExceptionReporter:71 - SQL Error: 1267, SQLState: HY000
12:00:23,296 ERROR JDBCExceptionReporter:72 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='
org.hibernate.exception.GenericJDBCException: could not execute query
 at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
 at org.hibernate.loader.Loader.doList(Loader.java:2147)
 at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
 at org.hibernate.loader.Loader.list(Loader.java:2023)
 at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
 at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
 at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
 at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
 at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
 at com.shop.dao.impl.LipinDaoImpl.findByBianhao(LipinDaoImpl.java:97)
 at com.shop.domain.logic.impl.LipinManagerImpl.findByBianhao(LipinManagerImpl.java:34)
 at org.apache.jsp.back_005fFriendSelect_jsp._jspService(back_005fFriendSelect_jsp.java:80)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
 at com.shop.commons.Chinese.doFilter(Chinese.java:22)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
 at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
 at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
 at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1125)
 at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:677)
 at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1222)
 at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
 at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
 at org.hibernate.loader.Loader.doQuery(Loader.java:662)
 at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
 at org.hibernate.loader.Loader.doList(Loader.java:2144)
 ... 43 more

 

 

 

 

到底怎么解决啊,网上搜的一些办法都不管用!

请高手们帮帮我,非常感谢!

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

F_F_B_M

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值