Hibernate Tools

2008-02-23 09:28:38来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Please note that this release is a preview release and considered alpha quality. The presented functionality (reverse engineering, code generation, etc.) is also be available outside of Eclipse, ie. as Ant tasks. See the Hibernate Tools website for more information about the road map.

1. Introduction

We have made significant improvements to the Hibernate toolset for Hibernate3. This is however work in progress and we'll continue to implement new ideas and features as the third generation of the Hibernate3 object persistence stack evolves.

The first set of tools we offer are plugins for the Eclipse IDE. The following features are available:

Mapping Editor: An editor for Hibernate XML mapping files, supporting auto-completion and syntax highlighting. It also supports semantic auto-completion for class names and property/field names, making it much more versatile than a normal XML editor.

Console: The console is a new view in Eclipse. In addition to a tree overview of your console configurations, you also get an interactive view of your persistent classes and their relationships. The console allows you to execute HQL queries against your database and browse the result directly in Eclipse.

Development Wizards: Several wizards are provided with the Hibernate Eclipse tools; you can use a wizard to quickly generate Hibernate configuration (cfg.xml) files, or you may even completely reverse engineer an existing database schema into POJO source files and Hibernate mapping files. The reverse engineering wizard supports customizable templates.

2. Requirements

  1. Install Eclipse 3.1 (http://www.eclipse.org)

After you have downloaded the Hibernate Tools for Eclipse, unpack and copy the plugins to your Eclipse plugins directory. Sometimes Eclipse does not automatically detect new plugins and thus the tools will not be activated. To ensure eclipse sees these changes run eclipse with the -clean option. E.g. eclipse -clean

You will also need JDBC drivers for your database available to use the reverse engineering and querying support.

Please note that these tools do not try to hide any functionality of Hibernate. The tools make working with Hibernate easier, but you are still encouraged/required to read the documentation for Hibernate to fully utilize Hibernate.

3. Creating a Hibernate configuration file

To be able to reverse engineer, prototype queries, and of course to simply use Hibernate a hibernate.properties or hibernate.cfg.xml file is needed. The Hibernate Tools provide a wizard for generating the hibernate.cfg.xml file.

Start the wizard by clicking "New Wizard" (Ctrl N), select the Hibernate/Hibernate Configuration file (cfg.xml) wizard and press "Next". After selecting the location for the hibernate.cfg.xml file, you will see the following page:


Creating hibernate.cfg.xml

Enter your configuration information in this dialog. Details about the configuration options can be found in Hibernate reference documentation. Press "Finish" to create the configuration file, it will be automatically opened in an editor.

Tip: The contents in the combo boxes for the JDBC driver class and JDBC URL change automatically, depending on the Dialect and actual driver you have chosen.

4. XML Mapping Editor

The XML mapping editor provides basic XML editing functionality as well as package, class, and field completion for relevant XML attributes. The auto-completion detects it's context and limits the completion for e.g. <property> and only shows the properties/fields available in the enclosing <class>, <subclass> etc.


Context dependent code completion in the XML mapping editor

5. Hibernate Console perspective

The Hibernate Console perspective combines a set of views which allow you to see the structure of your mapped entities/classes, edit HQL queries, execute the queries, and see the results. To use this perspective you need to create a console configuration.

5.1 Creating a console configuration

You create a console configuration by running the Console Configuration wizard, shown in the following screenshot:


Creating a Hibernate Console configuration

The following table describes the available settings. The wizard can automatically detect default values.

ParameterDescriptionAutodetectNameThe unique name of the configurationName of the Java projectProperty filePath to a hibernate.properties file/td> First hibernate.properties file found in the projectConfiguration filePath to a hibernate.cfg.xmlFirst hibernate.cfg.xml found in the projectMapping filesList of additional mapping files that should be loaded. Note: A hibernate.cfg.xml can also contain mappings, avoid duplication.All hbm.xml files found in the projectClasspathThe classpath for loading POJO and JDBC drivers. Don't add Hibernate core libraries or dependencies, they are already included.The default build output directory and any JARs with a class implementing java.sql.Driver

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Java数据库接口JDBC入门基础讲座

下一篇:Tomcat中JDBCRealm的配置