_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy异常

来源:互联网 发布:ubuntu jdk 1.7 下载 编辑:程序博客网 时间:2024/05/16 02:36

hibernate的级联查询测试代码:
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(locations = "classpath:applicationContext.xml")
  3. public class Mytest {
  4. @Resource
  5. private CategoryService categoryService;
  6. @Test
  7. public void testQueryJoinAccount(){
  8. for(Category c:categoryService.queryJoinAccount("装")){
  9. System.out.println(c);
  10. System.out.println(c.getAccount());
  11. }
  12. }
  13. }
报错结果:
Hibernate: select category0_.id as id1_1_, category0_.aid as aid4_1_, category0_.hot as hot2_1_, category0_.type as type3_1_ from category category0_ where category0_.type like ?
22:02:12.553 [main] ERROR org.hibernate.proxy.pojo.javassist.JavassistProxyFactory - HHH000142: Javassist Enhancement failed: com.model.Account
java.lang.ClassCastException: com.model.Account_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy

原因:ManyToOne中即多的一方启用的fetch抓取策略是懒加载FetchType.LAZY
         One的一方启用的fetch抓取策略是立即加载FetchType.EAGER

 
 
在JPA的hibernate级联查询中:保持Many的一方为立即加载,错误立马解决
PS:我也不知道为什么,只是无意中改成这样子就成功了!
阅读全文
0 0
原创粉丝点击