| At line 61 added 51 lines. |
|
| 这个类必须扩展[BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/model/BaseObject.java.html],而这个 |
|
| BaseObject有三个抽象方法(equals(), hashCode() and toString())需要你在Person类里实现,前两个是Hibernate的需要。为了完成这部分 |
|
| 工作最简单的方式是使用[Commonclipse|http://commonclipse.sf.net],关于这个工具更多的信息可以在[Lee Grey的网站 |
|
| |http://www.leegrey.com/hmm/2004/09/29/1096491256000.html]里看到,另外一个你可以使用的Eclipse的插件是 |
|
| [Commons4E|http://commons4e.berlios.de/],我还没有使用过,这里不便对其功能作出评论。 |
|
| ;:''如果你使用[IntelliJ IDEA|http://www.jetbrains.com/idea],你可以自动产生equals()和hashCode(),但没有toString(),有一个 |
|
| [ToStringPlugin|http://www.intellij.org/twiki/bin/view/Main/ToStringPlugin]插件做得非常不错'' |
|
| 现在我们已经创建了这个POJO对象,我们需要增加XDoclet标记来产生Hibernate的映射文件,这些文件用来映射对象→ 表和属性(变量) |
|
| → 字段。 |
|
| 首先,我们增加[@hibernate.class|http://xdoclet.sourceforge.net/tags/hibernate-tags.html#@hibernate.class%20(0..1)] 来告诉 |
|
| Hibernate我们将要和那个表作关联: |
|
| [{Java2HtmlPlugin |
|
| /** |
| * @hibernate.class table="person" |
| */ |
| public class Person extends BaseObject { |
| }] |
|
| We also have to add a primary key mapping or XDoclet will puke when generating the mapping file. Note that all @hibernate.* |
|
| tags should be placed in the __getters'__ Javadocs of your POJOs. |
|
| [{Java2HtmlPlugin |
|
| /** |
| * @return Returns the id. |
| * @hibernate.id column="id" |
| * generator-class="increment" unsaved-value="null" |
| */ |
|
| public Long getId() { |
| return this.id; |
| } |
| }] |
|
| ;:%%(color: blue)''我使用{{generator-class="increment"}}而不使用{{generate-class="native"}} 是因为我对数据库使用"native"时[发 |
|
| 现了一些问题|AppFuseOnDB2],如果你只是希望使用MySQL,推荐使用"native"值__,本教程使用increment。''%% |