解决方案 »
- 请教spring2.5 mvc中 关于注解的用法
- [急]2个String(其实是IPv6地址)如何进行大小比较
- 如何获取XML中带:冒号的节点值?
- 关于spring的问题 !! 急 ,解决就给分
- 初学SPRING`做的一个国际化的例子`中文怎么会是乱码?
- 急
- 急问:用jdbc与sqlserver连接时出现的问题?
- Open Source 开源组合( Spring+Struts+Hibernate )!
- 用jdom生产xml文件,怎么把xml-stylesheet","href=\"test1.xsl\" type=\"text/xsl\加到xml文件的头部?
- myeclipse不能调试JSP 和JS
- 请教一个jbpm4.4的问题,关于任务分配者的。
- Hibernate 注解@ManyToOne
仍然报错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
结贴,给分。