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!
相关推荐
不喜欢使用myEclipse的...最近在项目中使用Hibernate,由于需要使用HQL,找了很多资料,大都是MyEclipse中自带的HQL工具。 由于MyEclipse是收费的,速度不是很理想。所以在网上找到了一个elipse插件 英文图文教程 ...
在实际开发中,结合提供的文档“Hibernate_Tools_for_Eclipse插件的安装和使用.doc”,可以更深入地理解和掌握插件的使用技巧,进一步提升开发体验。同时,记得及时关注官方更新,以获取最新的特性和修复。
6. **JPA支持**:除了传统的Hibernate映射,Hibernate Tools还支持Java Persistence API(JPA),可以生成JPA实体类和配置文件,与JPA标准兼容。 7. **插件安装和管理**:`features`目录下的文件用于定义Eclipse...
接下来,我们转向Hibernate,这是一个强大的ORM(对象关系映射)框架,使得开发者可以在Java中使用面向对象的方式来操作数据库。与Struts结合,能有效提升开发效率和代码的可维护性。 6. **Hibernate配置**:在`...
1.2 JDK 的下载,安装和配置(可选) 18 1.2.1下载JDK 18 1.2.2 安装JDK 23 1.2.3 配置环境变量(可选) 24 1.2.4 JDK 6 中文文档下载地址(ZIP,HTML,CHM)(可选) 26 1.3 Tomcat服务器的下载,安装和运行(可选) 26 ...
开发环境一般使用Eclipse,配合相关插件,如: - **tomcatPluginV31**:方便Tomcat项目的管理和部署。 - **Properties Editor**:帮助处理Struts资源国际化。 - **xmlbuddy_2.0.72**:XML编辑器。 - **GEF-SDK**和...
- EULA(End User License Agreement)则是对最终用户使用软件的条款进行定义,尽管jBPM作为开源项目,其EULA更多是指明用户如何合法地使用和分发该软件。 - **1.2 下载资源** - 提供了多种下载选项,包括源代码...
4. **配置文件**: 修改`web.xml`和`applicationContext.xml`等配置文件,集成Spring和其他框架。 5. **编写业务逻辑**: 实现具体的业务逻辑代码,包括权限管理等功能。 6. **测试**: 对项目进行全面测试,确保各项...