即使把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]
改完了还是出错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]
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
谢谢,还是有问题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]
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; }}
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
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
多谢各位好朋友们的帮忙,我的问题搞定了 因为配置文件中已经关联的两者,所以直接采用对象导航就可以了,sql语句中的on条件是不用写的,hql智能的加上了,如果有where条件,加上就可以了。以下是我的解决方法。select a,b from Authority a left join a.authority b 结贴,给分。
仍然报错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]
改完了还是出错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]
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]
<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>
看下你这个类
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;
}}
改为:
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
<column name="parentRightID" />
</many-to-one>没看出来你配置这个有啥用
many-to-one 是one一端配置的,one-to-many是many端配置的,只不过同一张表而已嘛
貌似hql语句左连接不应该有on出现
先试试前面,
再看添加条件 where b.id is not null
因为配置文件中已经关联的两者,所以直接采用对象导航就可以了,sql语句中的on条件是不用写的,hql智能的加上了,如果有where条件,加上就可以了。以下是我的解决方法。select a,b from Authority a left join a.authority b
结贴,给分。