hibernate 官方入门教程第一部分 - 第一个 Hibernate 程序首先我们将创建一个简单的控制台(console-based)Hibernate 程序。我们使用内置数据库(in-memory database) (HSQL DB),所以我们不必安装任何数据库服务器。让我们假设我们希望有一个小程序可以保存我们希望关注的事件(Event)和这些事件的信息。 (译者注:在本教程的后面部分,我们将直接使用 Event 而不是它的中文翻译“事件”,以免混淆。)我们做的第一件事是建立我们的开发目录,并把所有需要用到的 Java 库文件放进去。 从Hibernate 网站的下载页面下载 Hibernate 分发版本。解压缩包并把/lib 下面的所有库文件放到我们新的开发目录下面的/lib 目录下面。 看起来就像这样:.+lib antlr.jarcglib-full.jarasm.jarasm-attrs.jarscommons-collections.jarcommons-logging.jar ehcache.jar hibernate3.jar jta.jar dom4j.jar log4j.jarThis is the minimum set of required libraries (note that we also copied hibernate3.jar, the mainarchive) for Hibernate. See the README.txt file in the lib/ directory of the Hibernate distributionfor more information about required and optional third-party libraries. (Actually, Log4j is notrequired but preferred by many developers.) 这个是 Hibernate运行所需要的最小库文件集合(注意我们也拷贝了 Hibernate3.jar,这个是最重要的库)。可以在 Hibernate 分发版本的 lib/目录下查看 README.txt,以获取更多关于所需和可选的第三方库文件信息 (事实上,Log4j并不是必须的库文件但是许多开发者都喜欢用它)。接下来我们创建一个类,用来代表那些我们希望储存在数据库里面的 event.2.2.1. 第一个 class我们的第一个持久化类是 一个简单的 JavaBean class,带有一些简单的属性(property)。 让我们来看一下代码:import java.util.Date;public class Event {private Long id;private String title;private Date date;Event() {}public Long getId() {return id;}private void setId(Long id) {this.id = id;}public Date getDate() {return date;}public void setDate(Date date) {this.date = date;}public String getTitle() {return title;}public void setTitle(String title) {this.t...