HIbernate符合Java习惯的关系数据库持久化之Persistent
实现一个默认的(即无参数的)构造方法(constructor)
Cathas a no-argument constructor. All persistent classes must have adefault constructor (which can be non-public) so that Hibernate caninstantiate them using Constructor.newInstance(). It is recommended that you have a default constructor with at least package visibility for runtime proxy generation in Hibernate
所有持久化类必须有一个默认无参构造器,可以不是公共的以便HIbernate实例化。
提供一个标识属性(identifier property)(可选)
标识符属性是可选的。可以不用管它,让Hibernate内部来追踪对象的识别。 但是我们并不推荐这样做。
In fact, some functionality is available only to classes that declare an identifier property:
Transitive reattachment for detached objects (cascade update or cascade merge)?
Session.saveOrUpdate()
Session.merge()
Werecommend that you declare consistently-named identifier properties onpersistent classes and that you use a nullable (i.e., non-primitive)type.
推荐声明主键
使用非final的类 (可选)
代理(proxies)是Hibernate的一个重要的功能,它依赖的条件是,持久 化类或者是非final的,或者是实现了一个所有方法都声明为public的接口。
You can persist finalclasses that do not implement an interface with Hibernate. You willnot, however, be able to use proxies for lazy association fetchingwhich will ultimately limit your options for? performance tuning.
可以不通过接口实现持久化,
你也应该避免在非final类中声明 public final的方法。如果你想使用一 个有public final方法的类,你必须通过设置lazy="false" 来明确地禁用代理。
为持久化字段声明访问器(accessors)和是否可变的标志(mutators)(可选)
Catdeclares accessor methods for all its persistent fields. Many other ORMtools directly persist instance variables. It is better to provide anindirection between the relational schema and internal data structuresof the class. By default, Hibernate persists JavaBeans style propertiesand recognizes method names of the form getFoo, isFoo and setFoo. If required, you can switch to direct field access for particular properties.
属性不需要要声明为public的。Hibernate可以持久化一个有 default、protected或private的get/set方法对 的属性进行持久化。