hibernate perfer non-final class的大致意思

最近没事,回头看hibernate的手册,发现这么一段
4.1.3. Prefer non-final classes (semi-optional)

A central feature of Hibernate, proxies (lazy loading), depends upon the persistent class being either non-final, or the implementation of an interface that declares all public methods. You can persist final classes that do not implement an interface with Hibernate; you will not, however, be able to use proxies for lazy association fetching which will ultimately limit your options for performance tuning. To persist a final class which does not implement a "full" interface you must disable proxy generation. See 例 4.2 “Disabling proxies in hbm.xml” and 例 4.3 “Disabling proxies in annotations”.

例 4.2. Disabling proxies in hbm.xml


<class name="Cat" lazy="false"...>...</class>

例 4.3. Disabling proxies in annotations

@Entity @Proxy(lazy=false) public class Cat { ... }

If the final class does implement a proper interface, you could alternatively tell Hibernate to use the interface instead when generating the proxies. See 例 4.4 “Proxying an interface in hbm.xml” and 例 4.5 “Proxying an interface in annotations”.

例 4.4. Proxying an interface in hbm.xml


<class name="Cat" proxy="ICat"...>...</class>

例 4.5. Proxying an interface in annotations

@Entity @Proxy(proxyClass=ICat.class) public class Cat implements ICat { ... }

You should also avoid declaring public final methods as this will again limit the ability to generate proxies from this class. If you want to use a class with public final methods, you must explicitly disable proxying. Again, see 例 4.2 “Disabling proxies in hbm.xml” and 例 4.3 “Disabling proxies in annotations”.看了半天也没明天是怎么回事,
找了又找,终于晓得,还原是生成代理的时候要继承自该pojo,所以有final会覆盖不了该方法,不是怎么样来着。他也没说清。唉,英语呀,永远的痛呀

你可能感兴趣的:(Hibernate,non-final class,prefer)