使用ssh框架和idea的一切问题总结

1 hibernate创建表失败 因为isread属性自动生成的set get方法名字得不到属性值

2 依赖注入失败因为 没用接口声明要注入的对象 jdk动态代理无法注入

3 manyToone 不能和column一起用

 4 Hibernate批量删除出现sql异常Connection is read-only. Queries leading ... are not allowed

spring配置文件中声明式事务声明的方法设置了只读 但是这个方法不是只读操作是删除或者添加或者修改

 

5 IDEA自动生成的equals方法有问题 that.id不对, 因该是that.getId() eclipse也有这个问题

 

6 当使用hibernate时 有 2张表关联,只取其中一张表的数据如果不用 left join fetch 抓取另一张表。有时多发一条SQL,但是又没有必要抓取另一张表

这时使用,select new xxx() 方法构造取出表中的数据,类中要有相应的构造方法

 

7两条hql语句。被注释的竟然无效。已经解决 看9

/* String hql = "select  doc " +
            "from UserReadDoc urd " +
            "left join fetch urd.document doc " +
            "left join fetch doc.user u " +
            "left join fetch u.department dep " +
            "where urd.user.id=?";*/
      String hql = "select doc from Document doc  " +
              "left join fetch doc.user u " +
              "left join fetch u.department dep " +
              "where doc.id in (select urd.document.id from UserReadDoc urd where urd.user.id=?)";

8 Struts2的action乱码,本来配置了spring的过滤器不会有乱码了。但是还有。这回把tomcat里的server.xml文件也修改了

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" useBodyEncodingForURI="true" URIEncoding="UTF-8" />

这回乱码解决了。原因待查

9.今天报了这个异常 解决地址 http://blog.csdn.net/wherejaly/article/details/4468772

 

org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the sel

错误原因分析:

      首先看HQL语句:

       SELECT pfp.tprofile FROM Tprofileperson pfp left join fetch pfp.tprofile WHERE pfp.tperson.personid = 114

      此处我希望加载Tprofileperson下的tprofile,而我使用了fetch来立即抓取tprofile,错误就在这里.如果你使用 fetch,那么fetch左边的连接对象(拥有者)一定要出现在select后,例如将上面改为select pfp... 这样就会执行正常,因为使用了fetch,Hibernate就会将需要fetch的对象(Tprofile)立即加载在父对象 (Tprofileperson)中,而我的select确只是列出子对象,而拥有者(Tprofileperson)并没有present(出席在结果 集中),那么就会出现以上错误.

     下面我们看另外会出现同样错误的语句:

    

  1. 01: select person from Person as person  
  2. 02: left join person.address as address  
  3. 03: left join fetch address.country as country  

你可以看到在第3行使用了fetch,而第2行确没有使用fetch,那么第3行fetch的拥有者address并没有立即被抓取,这就会导致同样的错误,将第2行中的join后加上fetch,即可解决问题.

总结:

      如果使用了fetch,那么拥有者一定要present,也就是对象一定要被加载出来

 

 

posted on 2013-10-19 20:54  c3tc3tc3t  阅读(405)  评论(0)    收藏  举报