`
AlexanderMahone
  • 浏览: 8374 次
社区版块
存档分类
最新评论

eclipse 中 HQL editor 的配置 和使用

阅读更多

 

Link in : http://www.springwebdevelopment.com/using-hql-editor-in-hibernate-tools

Using HQL Editor in Hibernate Tools

For anyone who uses Eclipse and is also writing HQL, the Hibernate Tools HQL Editor is a very useful piece of software. The tool I have been using is the one provided by JBoss who also provide the popular Object Relational Mapping (ORM) tool Hibernate itself. The hibernate tools provide several utilities but Im just going to concentrate on the use of the HQL editor in this article.

The JBoss hibernate tools are a plugin for the Eclipse IDE. The first thing to do therefore is install them in Eclipse, and this is most easily done from within Eclipse using the Update Manager. At the time of writing the relevant information and update site are as follows:

information: http://docs.jboss.org/tools/2.1.0.GA/en/hibernatetools/html/setup.html

update site: http://download.jboss.org/jbosstools/updates/stable/

The versions of Eclipse and Hibernate Tools I am using for the purpose of this article are:

Eclipse Ganymede – 3.4.1

Hibernate Tools – 3.2.4

After you have installed Hibernate Tools in Eclipse go to Window > Open Perspective > Other > Hibernate

Now find the Hibernate Configurations view – it should open automatically with the perspective but you can also open it via Window > Show Viw> Other > Hibernate > Hibernate Configurations.

In the Hibernate Configurations view right-click (windows) on the hibernate node to open the context menu and select Add Configuration.

Main Tab

Select your project

If you are connecting to Hibernate then leave the database connection
as [Hibernate configured connection]

Now you need to setup your configuration file – click Setup next to the Configuration file field and selct Create new.

This file configures the hibernate session basically.

You need to provide the database driver details, authentication details, mapping file locations etc

Example hibernate.cfg.xml

<?xml version=’1.0′ encoding=’utf-8′?>

<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 3.0//EN”

“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>

<hibernate-configuration>

  <session-factory>

    <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>

    <property name=”connection.url”>jdbc:mysql://localhost:3306/myDataBase</property>

    <property name=”connection.username”>root</property>

    <property name=”connection.password”>password</property>

    <property name=”connection.pool_size”>1</property>

    <property name=”dialect”>org.hibernate.dialect.MySQL5InnoDBDialect</property>

    <property name=”current_session_context_class”>thread</property>

    <property name=”cache.provider_class”>org.hibernate.cache.NoCacheProvider</property>

    <property name=”show_sql”>true</property>

    <mapping resource=”com/myProject/entity/Result.hbm.xml”/>

    <mapping resource=”com/myProject/entity/Tag.hbm.xml”/>

    <mapping resource=”com/myProject/entity/TaggedResult.hbm.xml”/>

  </session-factory>

</hibernate-configuration>

 

Classpath Tab

You will need to add any dependant projects and libraries, namely the location of the database driver.

When you click OK in the Hibernate Configuration window – if all is well – the plugin should create a Session Factory and obtain a connection to the database and you should see 3 more nodes – Configuration, Session Factory and Database. If there are problems you will get some errors that you will need to resolve before you can proceed.

Once you have got the configuration right and have your Session Factory then right-click on any node and select HQL editor.

try a straightforward query to test things ie. if you have a table RESULT try typing “from Result2 in the HQL query window. Now click the green Run HQL arrow and you will be able to see the records returned in the Hibernate Query Result view (you may need to open this or it may be lurking behind other views). Youcan also see the SQL that Hibernate generates from the HQL you write in the Hibernate Dynamic SQL Preview view.

Happy HQL’ing!

分享到:
评论

相关推荐

    HQL Eclipse Plugins 配置教程

    不喜欢使用myEclipse的...最近在项目中使用Hibernate,由于需要使用HQL,找了很多资料,大都是MyEclipse中自带的HQL工具。 由于MyEclipse是收费的,速度不是很理想。所以在网上找到了一个elipse插件 英文图文教程 ...

    Eclipse中Hibernate简单配置和使用

    Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用,最具革命意义的是,Hibernate可以在应用EJB的J2EE架构中取代CMP,完成数据持久化的重任。 Hibernate...

    Eclipse 在线配置 Hibernate Tools

    通过以上步骤,你已经成功地在 Eclipse 中配置了 Hibernate Tools,现在可以利用其各种功能,如生成实体类、映射文件、HQL查询编辑器等,提高你的 Hibernate 开发效率。在实际开发中,熟悉和熟练使用这些工具将极大...

    HQL的具体内容和使用

    Hibernate Query Language(HQL)是Hibernate框架中专用于对象关系映射(ORM)的查询语言,它使得开发者能够以面向对象的方式来查询...掌握HQL可以帮助我们在使用Hibernate进行ORM开发时更加高效地进行数据查询和操作。

    hql语句 使用大全

    ### HQL语句使用大全 HQL(Hibernate Query Language)是一种面向对象的查询语言,它提供了灵活而强大的数据检索方式,使开发人员能够更高效地与数据库交互。本文将详细介绍HQL的基本用法及高级特性。 #### 1. ...

    HQL连接查询和注解使用总结

    - 在HQL查询语句的`WHERE`子句中使用子查询。 - 关键字`ALL`, `ANY`/`SOME`, `IN`, `EXISTS`等可以用于子查询。 - **HQL提供的集合操作函数**: - `size()`/`size`: 获取集合中元素的数目。 - `minIndex()`/`...

    Spring中hql语句的常用方法

    ### Spring框架中HQL语句的使用方法 在学习Spring框架与...以上就是在Spring框架中使用HQL进行数据查询的主要方法。通过这些方法,开发者可以根据不同的需求选择合适的查询方式,从而更加高效地完成数据处理任务。

    在eclipse中使用hibernate

    ### 在Eclipse中使用Hibernate的知识点详解 #### 1. 持久化框架产生的背景和现状 在Java开发过程中,特别是在涉及数据库交互时,由于数据库本身的特性(通常是关系型数据库),与Java语言的面向对象特性之间存在...

    Eclipse Hibernate基本配置及简单实现

    本篇将介绍如何在Eclipse环境中配置和使用Hibernate进行简单的数据操作。 ### 一、Hibernate环境搭建 1. **下载Hibernate**: 首先,我们需要从官方网站或Maven仓库下载Hibernate的JAR包,包括hibernate-core、...

    eclipse配置hibernate需要的jar

    总之,Eclipse中配置Hibernate涉及到多个jar包的导入和恰当的设置,这些包提供了ORM框架、日志记录、XML处理、事务管理以及数据库连接等功能,它们共同协作,使得在Java应用中轻松地管理和操作数据库成为可能。...

    HQL语句 HQL语句

    HQL语句 HQL语句 HQL语句 HQL语句 HQL语句

    HQL语句大全HQL语句大全

    ### HQL语句详解 #### 一、HQL简介 HQL(Hibernate Query Language)是Hibernate框架中的查询语言,它提供了面向对象的方式来进行数据库...在实际开发中,合理利用HQL可以极大地提高数据库操作的效率和代码的可读性。

    Hibernate_Tools_for_Eclipse插件的安装包和使用说明

    Hibernate Tools是Eclipse集成开发环境中的一款强大插件,它为开发者提供了方便的Hibernate实体类生成、数据库反向工程、SQL执行及对象关系映射(ORM)配置等多种功能。在本文中,我们将详细介绍如何安装Hibernate ...

    Hibernate查询语言HQL.PPT

    它提供了灵活多样的查询机制,包括导航对象图、通过标识符检索、使用 HQL 检索对象、使用 Hibernate 条件 API 和使用本地 SQL 查询等。 在 Hibernate 中检索对象的各种方法: 1. 导航对象图:通过对象的关联关系,...

    HQL语法入门学习HQL语法入门学习

    与SQL(Structured Query Language)不同,HQL是专为ORM(Object-Relational Mapping)设计的,它允许开发者以类和对象的方式而不是数据库表和字段来编写查询。 在Java开发中,Hibernate作为一个流行的ORM工具,...

    hql模糊查询hql模糊查询

    在这个示例中,我们首先定义了一个HQL查询字符串,该字符串指定了查询的类(Subject)以及模糊匹配的字段(subname 和 subinfo)。接着,我们通过`session.createQuery()`方法创建了一个`Query`对象,并使用`...

    Hibernate中HQL语句的使用[参考].pdf

    HQL语句的使用是Hibernate中最重要的部分之一,本文将详细介绍HQL语句的使用方法和示例。 简单属性查询 HQL语句可以用于查询实体类中的简单属性,例如: ```java List students = session.createQuery("select ...

    HQL批量插入、更新和删除

    ### HQL批量插入、更新和删除 #### 一、概述 在进行数据库操作时,批量处理数据是一项常见的需求。为了提高效率并减少网络传输开销,HQL(Hibernate Query Language)提供了一种灵活的方式来实现这一目标。HQL是...

Global site tag (gtag.js) - Google Analytics