今天在查找Hibernate所出现的问题时,发现了其一个比较变态的设计及实现。
org.hibernate.proxy.EntityNotFoundDelegate接口,查了好久,没有发现它是由那个具体类实现的。如果一个接口没有具体实现,是不可能的,这是大家共知的常识,所以,还要仔细找找,可能是由inner class 实现的具体方法,可能就无法找到implements关键字了。根据这个思路,将Hibernate的源码,做了一个project在eclipse里,这样,利用eclipse强大的查找功能,找到了六处与字符串handleEntityNotFound匹配。
在org.hibernate.impl.SessionFactoryImpl类,看到了这么一段代码:进入org.hibernate.cfg.Configuration一看,对于entityNotFoundDelegate 只有一个setter和getter方法,没有具体实现。呵呵,看来,就是在SessionFactoryImpl里实现了这一点。但是,既然初始化了EntityNotFoundDelegate ,为何没有调用Configuration的setEntityNotFoundDelegate(EntityNotFoundDelegate entityNotFoundDelegate)方法进行设值呢?!!
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/1327ab569c1ae82736693a50b8e33378.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/7ff8d92cded7e0ce15e7ca1acc870052.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/7ff8d92cded7e0ce15e7ca1acc870052.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/717446ca04a6125dc5b6b54e0fa14ab4.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/717446ca04a6125dc5b6b54e0fa14ab4.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
应用这个接口里的方法,无非是为了抛出一个ObjectNotFoundException,只有大家明白了这点就行了。