本帖最后由 wuwenzhe 于 2013-04-17 18:36:48 编辑

解决方案 »

  1.   

    即使把HQL语句改写为String queryString = "select a.id,a.authority.id,a.name,a.description,b.id,b.name from Authority a left outer join Authority b where a.authority.id = b.id";
    仍然报错18:38:03,382 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Path expected for join!
    18:38:03,385 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Invalid path: 'b.id'
    18:38:03,386 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Invalid path: 'b.id'
    18:38:03,387 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  right-hand operand of a binary operator was null
    18:38:03,388 ERROR [dao.AuthorityDAO] (http--127.0.0.1-8080-1) find all failed: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [select a.id,a.authority.id,a.name,a.description,b.id,b.name from pojo.Authority a left outer join Authority b where a.authority.id = b.id]
      

  2.   


    改完了还是出错org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 111 [select a.id,a.authority.id,a.name,a.description,b.id,b.name from pojo.Authority a left outer join Authority b on a.authority.id = b.id]
      

  3.   

    select a.id,a.authority.id,a.name,a.description,b.id,b.name from Authority a left join Authority b on a.authority.id = b.id where a.authority.id is not null
      

  4.   

    谢谢,还是有问题08:22:49,281 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-2) line 1:105: unexpected token: on
    08:22:49,285 ERROR [dao.AuthorityDAO] (http--127.0.0.1-8080-2) find all failed: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 105 [select a.id,a.authority.id,a.name,a.description,b.id,b.name from pojo.Authority a left join Authority b on a.authority.id = b.id where a.authority.id is not null]
      

  5.   

    以下是配置文件,这个表自关联<hibernate-mapping>
        <class name="pojo.Authority" table="authority" schema="dbo" catalog="wgzxdms">
            <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="identity" />
            </id>
            <many-to-one name="authority" class="pojo.Authority" fetch="join">
                <column name="parentRightID" />
            </many-to-one>
            <property name="name" type="java.lang.String">
                <column name="name" />
            </property>
            <property name="description" type="java.lang.String">
                <column name="description" />
            </property>
            <set name="userAuthorities" inverse="true">
                <key>
                    <column name="rightID" />
                </key>
                <one-to-many class="pojo.UserAuthority" />
            </set>
            <set name="authorities" inverse="true">
                <key>
                    <column name="parentRightID" />
                </key>
                <one-to-many class="pojo.Authority" />
            </set>
            <set name="roleAuthorities" inverse="true">
                <key>
                    <column name="rightID" />
                </key>
                <one-to-many class="pojo.RoleAuthority" />
            </set>
        </class>
    </hibernate-mapping>
      

  6.   

    Authority 
    看下你这个类
      

  7.   

    public class Authority implements java.io.Serializable { // Fields private Integer id;
    private Authority authority;
    private String name;
    private String description;
    private Set userAuthorities = new HashSet(0);
    private Set authorities = new HashSet(0);
    private Set roleAuthorities = new HashSet(0); // Constructors /** default constructor */
    public Authority() {
    } /** minimal constructor */
    public Authority(Integer id) {
    this.id = id;
    } /** full constructor */
    public Authority(Integer id, Authority authority, String name,
    String description, Set userAuthorities, Set authorities,
    Set roleAuthorities) {
    this.id = id;
    this.authority = authority;
    this.name = name;
    this.description = description;
    this.userAuthorities = userAuthorities;
    this.authorities = authorities;
    this.roleAuthorities = roleAuthorities;
    } // Property accessors public Integer getId() {
    return this.id;
    } public void setId(Integer id) {
    this.id = id;
    } public Authority getAuthority() {
    return this.authority;
    } public void setAuthority(Authority authority) {
    this.authority = authority;
    } public String getName() {
    return this.name;
    } public void setName(String name) {
    this.name = name;
    } public String getDescription() {
    return this.description;
    } public void setDescription(String description) {
    this.description = description;
    } public Set getUserAuthorities() {
    return this.userAuthorities;
    } public void setUserAuthorities(Set userAuthorities) {
    this.userAuthorities = userAuthorities;
    } public Set getAuthorities() {
    return this.authorities;
    } public void setAuthorities(Set authorities) {
    this.authorities = authorities;
    } public Set getRoleAuthorities() {
    return this.roleAuthorities;
    } public void setRoleAuthorities(Set roleAuthorities) {
    this.roleAuthorities = roleAuthorities;
    }}
      

  8.   

    private Authority authority;在这个类中,定义这个对象,有意义吗?
    改为:
    select a.id,a.name,a.description,b.id,b.name from Authority a left join Authority b on a.id = b.id where a.id is not null
      

  9.   

    <many-to-one name="authority" class="pojo.Authority" fetch="join">
                <column name="parentRightID" />
            </many-to-one>没看出来你配置这个有啥用
      

  10.   


    many-to-one 是one一端配置的,one-to-many是many端配置的,只不过同一张表而已嘛
      

  11.   


    貌似hql语句左连接不应该有on出现
      

  12.   

    既然你都用了hibernate,父对象a.authority可以通过hibernate内部的机制获取,为啥还要自己写HQL?
      

  13.   

    select a.id,a.name,a.description,b.id,b.name from pojo.Authority as a left join a.authority as b
    先试试前面,
    再看添加条件 where b.id is not null
      

  14.   

    多谢各位好朋友们的帮忙,我的问题搞定了
    因为配置文件中已经关联的两者,所以直接采用对象导航就可以了,sql语句中的on条件是不用写的,hql智能的加上了,如果有where条件,加上就可以了。以下是我的解决方法。select a,b from Authority a left join a.authority b
    结贴,给分。