3.0 alpha 1, 25. January 2005
Please note that this release is a preview release and considered alpha quality. The presented functionality (reverse engineering, code generation, etc.) will soon 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
- Install Eclipse 3.1M4 (http://www.eclipse.org)
- Install JBoss Eclipse IDE 1.4.x - required for the mapping file editor (http://www.jboss.org/)
After you have downloaded the Hibernate Tools for Eclipse, unpack and copy the plugins to your Eclipse plugins directory. 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.xmlEnter 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 editor5. 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 configurationThe following table describes the available settings. The wizard can automatically detect default values.
ParameterDescriptionAutodetect
Name | The unique name of the configuration | Name of the Java project |
Property file | Path to a hibernate.properties file/td> | First hibernate.properties file found in the project |
Configuration file | Path to a hibernate.cfg.xml | First hibernate.cfg.xml found in the project |
Mapping files | List 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 project |
Classpath | The 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 |
Clicking "Finish" creates the configuration and shows it in the Console overview.
5.2 Viewing the entity structure
To view your new configuration and entity/class structure, right click the configuration in the list and select "Create SessionFactory". This will create a standard Hibernate SessionFactory using your settings.
Clicking on the small + symbol allows you to browse the class/entity structure and see the relationships.
Errors during creation of the SessionFactory (e.g. if your configuration is incorrect) will be shown in a message dialog, you may get more information about the error in the Error Log view on the right pane.
Hibernate Console perspective showing entity structure, query editor and result5.3 Prototyping Queries
Queries can be executed in two ways: by double clicking on entity names in the tree or by entering HQL in the HQL editor and pressing the green execute button.
Results of a query will be shown in the Query result view and details of possible errors (syntax errors, database errors, etc.) can be seen in the Error Log view.
Tip: HQL queries are executed using list() and without any limit of the size of the output. Be careful if you execute a query on a large result set. You might run out of memory. This will be improved in a future version.
6. Reverse engineering and code generation
A very simple "click-and-generate" reverse engineering and code generation facility is also available. The reverse engineering internally creates a Hibernate meta model. On this meta-model a set of (velocity) templates are applied, generating a set of artifacts. Currently supported are POJO Java source file, Hibernate *.hbm.xml, and hibernate.cfg.xml generation. To start this process, choose the "Hibernate Artifact Generation Wizard".
Artifact Generation WizardFirst select which Console configuration should be used and the target directory for code and mapping file generation. Note: Generation will generate files, and overwrite possibly existing files in this location.
Now choose from the following list of options:
6.1 Reverse engineering
Reverse engineering will connect to your database and read the JDBC metadata of your database schema. The basic rules for the conversion is that each table/view found is mapped to a POJO class, and each column is mapped to a property. The package name controls the "root" package of the generated classes.
For each found foreign key, a <many-to-one> and a corresponding <one-to-many> mapping, using a Set, will be created.
The flag "Generate 'raw' composite ids" turns on special handling of composite primary keys. A <composite-id> mapping will always be created, and if there are matching foreign-keys, a <key-many-to-one> will be created as well. If you choose to active the 'raw' composite ids, then each composite key column is considered a 'raw' scalar (string, long, etc.) instead of a reference to an entity. Note: a <many-to-one> property is still created, but is simply marked as non-updatable and non-insertable.
6.2 POJO code generation
The code generation will generate all the persistent classes and components found in the given Hibernate configuration.
You can use the code generation on your own handwritten or reverse-engineered mapping files.
This "EJB3/JSR-220 annotations" option will activate usage of the EJB3 sections in the javaclass.vm template. This is considered experimental and currently incomplete. Updates to the template are expected, you can even write (and hopefully contribute) more powerful templates.
The Java code generation is based on a a complete rewrite of the hbm2java found in the Hibernate 2.x toolset. This means that feature-wise they should be equal, but there might be some exotic <meta> features not fully implemented so far. Please report any bugs or missing code generation features via our issue tracking system.
Consult the Hibernate documentation for the various code generation tags you can use in your mapping files.
6.3 Hibernate Mapping file generation
This creates a hbm.xml for each class declared in the configuration (and their persistent subclasses). Each <subclass> or <joined-subclass> will be written to a separate mapping file, an extends attribute is used.
The mapping file generation feature currently supports only basic generation, completing the reverse engineering functionality. More features will be added in the future.
6.4 Hibernate configuration file generation
This option writes a hibernate.cfg.xml with all relevant properties and with a <mapping> reference for each persistent class
6.5 Custom templates
All of the generated code is controlled via templates (except the hibernate.cfg.xml). The wizard searches for the templates in the classpath of the plugin, by default.
You can customize templates by placing your own .vm files in a directory and naming the directory in the wizard dialog. You can override existing templates by using the same file names. The built-in templates can be found in the hibernate-tools.jar in the org.hibernate.eclipse plugin directory.
You may use a pre-defined set of variables and properties in templates, as shown in the following table.
NameContentsAvailability
$cfg | The current Hibernate Configuration object. See Hibernate3 javadocs for available properties/methods. | Anywhere |
$c2h | A Cfg2HbmTool. Contains a set of helper methods related to cfg to hbm conversion. See sourcecode and existing templates for available properties/methods. | Anywhere |
$c2j | A Cfg2JavaTool. Contains a set of helper methods related to cfg to java conversion. See sourcecode and existing templates for available properties/methods. | Anywhere |
$clazz | A reference to the current PersistentClass or Component being processed. | In any class related template |
$property | A reference to the current Property being processed | In any property related template |
Note that some of these properties are only available in a certain context (e.g. $property is not available at the Class level, but only fo rproperties). If you need to look up some information, you have full access to Hibernate's own meta-model, the Configuration via $cfg. This combined with the power of velocity templates should give you virtually unlimited flexibility and possibilities for code generation.
Note that we expect significant changes to the structure and organization of the built-in templates in one of the next releases.
--
相关推荐
HibernateTools是Java开发人员在使用Hibernate ORM框架时的有力辅助工具集,主要目的是为了提高开发效率,简化数据库操作。在HibernateTools 3.2.4版本中,它包含了一系列的特性与插件,以支持更便捷地进行对象关系...
hibernate-tools.jar
3. 数据库反向工程:在新版本中,Hibernate-tools的数据库反向工程功能更加完善,可以生成与现有数据库结构匹配的完整ORM模型,包括实体类、映射文件和配置文件,极大地简化了项目的初始化过程。 4. 源码兼容性:...
Hibernate Tools 是一个强大的开发工具,它为Hibernate ORM框架提供了丰富的集成开发环境支持,包括逆向工程(从数据库生成实体类)、代码生成、JPA支持以及HQL和SQL查询的调试等。要运行或修改Hibernate Tools的...
**Hibernate Tools使用指南** 在Java开发中,Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了数据库操作。为了提升开发效率,Hibernate提供了一系列的工具,即Hibernate Tools,帮助开发者进行逆向...
3. 你会看到一个名为 "Hibernate Tools" 的插件,它是 JBoss 开发的。选择 "Install" 来开始安装过程。 4. 选择你需要的组件,通常是 "Hibernate Tools",然后按照向导的提示逐步完成安装。 5. 安装完成后,Eclipse ...
hibernate-tools-4.0.0.jar官网下载
【hibernate tools插件安装】是关于Java开发中的一款实用工具,主要目的是为了提高开发效率,特别是针对使用Hibernate框架的项目。Hibernate Tools是Hibernate官方提供的一个扩展,它集成了Eclipse、IntelliJ IDEA等...
**hibernateTools3.3** 是一个针对Hibernate框架的扩展工具集,它极大地简化了开发者在使用Hibernate时的一些常见任务。最新版本的hibernateTools3.3旨在提供更高效、更稳定以及更多功能的支持,以提升开发者的生产...
hibernate-tools.jar
3. **Hibernate Tools安装**:在Eclipse中,可以通过“Help” > “Eclipse Marketplace”或“Install New Software”菜单项来搜索并安装Hibernate Tools插件。 4. **模型类生成**:Hibernate Tools可以根据现有...
3. **Oracle中文注解支持**:针对Oracle数据库,Hibernate Tools已经做了优化,可以在生成的Java实体类中添加中文注解,以便更好地支持中文列名和表名。这解决了使用Oracle数据库时中文字符编码的问题,提高了代码的...
**自定义 Hibernate Tools 模板**是针对 Eclipse 开发环境中的 Hibernate 工具集进行的一种扩展,目的是在使用 Hibernate 逆向工程(Reverse Engineering)生成实体类时,能够根据数据库中的注释自动添加对应的注释...
hibernate-tools-5.6.6.Final
3. 将 features 和 plugins 文件夹复制到 Hibernatetools 目录下。 4. 在 Eclipse 目录下建立 links 文件夹,并在 links 文件夹下建立 hibernatetools.link 文件,输入 Hibernatetools 的绝对目录。 5. 重新启动 ...
【hibernate Tools】是Java开发中用于简化Hibernate框架使用的工具集,它为Eclipse提供了对Hibernate项目的集成支持。在本文中,我们将详细介绍如何安装和使用hibernate Tools,以便在开发过程中更高效地处理...
下载并安装hibernate tools插件,下载地址:...安装完Hibernate tools插件后,在eclipse安装目录下搜索并替换hibernate-tools-5.2.0.Beta1.jar文件,即可生成带中文注释的类和hbm文件
《Hibernate Tools 3.1.0.beta5:Eclipse中的高效开发助手》 Hibernate Tools是Hibernate框架的一个扩展,它为开发者提供了在Eclipse集成开发环境中(IDE)进行更高效、更便捷的Hibernate应用开发的支持。这个版本...