`
Tian.Wang
  • 浏览: 71454 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

hibernate

 
阅读更多
最近在做自己项目的时候遇到的问题越来越多,网上查的资料,解决的方案也很多,总能找到我想要的,但是渐渐发现收藏夹里的网址都拉到屏幕低下了,为了防止信息丢失,我觉得有必要做点笔记了,这文章主要记录hibernate使用中的问题,可能以前也遇到过,但是时间久了老是忘记,这里做个备案。以上资料均为网上收集,仅供参考,不付技术责任。

    问题一,

                    
view plain
如果运行hql语句,比如"from po.test where test.name = sdf"  
不管是直接用HibernateTemplate还是用回调,都会报下面这个错  
 
org.hibernate.QueryException: Unable to resolve path [test.name], unexpected token [test] [SELECT  *  from po.test where test.name = sdf]  


   解决方法:

          就从你的这句HQL来分析原因吧: "from po.test where test.name = sdf"  sdf是个字符串值,应该加单引号。不然Hibernate会把它作为类的属性看待,而你的类中是没有sdf这个属性的 ,from后直接写类名,不必加包名 ,test是类名,不能直接使用test.name(不能通过类来访问,就好像你不能通过类名去访问实例变量一样),请不要问为什么,记住这是HQL的语法要求就行了。 那怎么办呢?通常会用别名的方式解决,比如 from test as t where t.name = 'sdf'(别名就好像是test类的一个对象,通过对象就可以访问实例变量啦,哈哈) 所以你也可以这样写: from test as test where test.name = 'sdf'(注意现在test.name中的test是别名了)
当然,仅对一个类进行操作,也可以不借助于别名: rom test where name = 'sdf'


原文地址:http://topic.csdn.net/u/20081016/19/0358d370-02bf-4f68-9654-2b6fbf0832ef.html
分享到:
评论

相关推荐

    hibernate jar包:hibernate-commons-annotations-4.0.1.Final.jar等

    Hibernate.jar包,Hibernate可以应用在任何使用JDBC的场合,包含 hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.1.12.Final.jar hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-...

    最新版本的Struts2+Spring4+Hibernate4框架整合

    项目原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6 二、 项目目的: 整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + ...

    hibernate.5.1.0.jar全部

    包含hibernate所有所需jar包还有一些其他包日志包、jpa支持包等: 列如:hibernate-core-5.1.0.Final.jar hibernate-ehcache-5.1.0.Final.jar hibernate-entitymanager-5.1.0.Final.jar hibernate-envers-5.1.0....

    Hibernate连接SQLite配置说明和方言代码

    Hibernate连接SQLite配置步骤: 1、添加SQLite库: 1.1、将两个jar包:com.zy.hibernate.dialect.SQLiteDialect.jar、sqlite-jdbc-3.7.2.jar拷贝到“\WEB-INF\lib”文件夹下; 2、配置hibernate: 2.1、将...

    Java Persistence WIth Hibernate 2nd

    Manning出版 Java Persistence With Hibernate 第二版 清晰pdf Hibernate, an open source project that is almost 15 years old. In a recent poll, Hibernate was among the top five tools used by many Java ...

    Could not roll back Hibernate transaction.doc

    Hibernate事务回滚失败解决方案 Hibernate是一个流行的Java持久层框架,它提供了对数据库的操作和事务管理机制。然而,在使用Hibernate时,可能会遇到事务回滚失败的问题,本文将详细介绍该问题的原因和解决方法。 ...

    hibernate-testjar包

    hibernate

    论坛系统项目(Struts 2+Hibernate+Spring实现)

    论坛系统项目(Struts 2+Hibernate+Spring实现)论坛系统项目(Struts 2+Hibernate+Spring实现)论坛系统项目(Struts 2+Hibernate+Spring实现)论坛系统项目(Struts 2+Hibernate+Spring实现)论坛系统项目(Struts...

    hibernate 资料hibernate 资料hibernate 资料

    hibernate 资料hibernate 资料hibernate 资料hibernate 资料

    hibernate关联映射详解

    hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,hibernate,包含4个说明文档,分别详细解说了hibernate...

    Hibernate连表查询 Hibernate连表查询

    Hibernate连表查询 Hibernate连表查询

    java persistence with hibernate

    Java Persistence with Hibernate is the new bible of Hibernate. As a major revision of the popular Hibernate in Action, it builds on the same single example application to introduce and explain the ...

    hibernate关系映射网址

    hibernate

    Hibernate稳定版(hibernate-release-5.3.23.Final.zip)

    Hibernate稳定版(hibernate-release-5.3.23.Final.zip),Hibernate ORM 是一个为应用程序、库和框架提供对象/关系映射 (ORM) 支持的库。它还提供了 JPA 规范的实现,这是 ORM 的标准 Java 规范。

    hibernate4.3完整jar包

    Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库。 Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端...

    Hibernate Hibernate5 讲义 PDF

    hibernate5 hibernate PDF 讲义 动力 hibernate ssh hibernate5 节点

    hibernate annotation hibernate3

    hibernate annotation hibernate3

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    深入浅出Hibernate(PDF)第一部分

    本书内容深入浅出,先讲述持久层设计与ORM,再由Hibernate概述、Hibernate基础Hibernate高级特性顺序展开,直至Hibernate实战,重点讲述了Hibernate的基础语法、基础配置、O/R映射、数据关联、数据检索、HQL实用技术...

    Hibernate对象的生命周期

    Hibernate对象的生命周期 Hibernate对象的生命周期 Hibernate对象的生命周期

Global site tag (gtag.js) - Google Analytics