Hibernate HQL语句和映射类错误

salana 2010-06-10 04:50:48
java代码:
StringBuffer hql = new StringBuffer("SELECT t FROM Citylist t, Employeecityref e WHERE t.citycode = e.citycode and e.employeeid ='"+emp.getEmployeeid()+"'");
List<Citylist> list = getSession().createQuery(hql.toString()).list();



出错信息:
org.hibernate.QueryException: could not resolve property: citycode of: com.palmcity.model.Employeecityref [SELECT t FROM com.palmcity.model.Citylist t, com.palmcity.model.Employeecityref e WHERE t.citycode = e.citycode and employeeid ='35']


由于Employeecityref表中没有ID所以映射表有两个Employeecityref.java,EmployeecityrefID.java
请问我的HQL 语句怎么写才能把Citylist调出来
...全文
88 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
salana 2010-06-11
  • 打赏
  • 举报
回复
package com.palmcity.model;

/**
* Employeecityref entity. @author MyEclipse Persistence Tools
*/

public class Employeecityref implements java.io.Serializable {

// Fields

private EmployeecityrefId id;

// Constructors

/** default constructor */
public Employeecityref() {
}

/** full constructor */
public Employeecityref(EmployeecityrefId id) {
this.id = id;
}

// Property accessors

public EmployeecityrefId getId() {
return this.id;
}

public void setId(EmployeecityrefId id) {
this.id = id;
}

}

package com.palmcity.model;

import java.math.BigDecimal;

/**
* EmployeecityrefId entity. @author MyEclipse Persistence Tools
*/

public class EmployeecityrefId implements java.io.Serializable {

// Fields

private Long employeeid;
private String citycode;

// Constructors

/** default constructor */
public EmployeecityrefId() {
}

/** full constructor */
public EmployeecityrefId(Long employeeid, String citycode) {
this.employeeid = employeeid;
this.citycode = citycode;
}

// Property accessors

public Long getEmployeeid() {
return this.employeeid;
}

public void setEmployeeid(Long employeeid) {
this.employeeid = employeeid;
}

public String getCitycode() {
return this.citycode;
}

public void setCitycode(String citycode) {
this.citycode = citycode;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof EmployeecityrefId))
return false;
EmployeecityrefId castOther = (EmployeecityrefId) other;

return ((this.getEmployeeid() == castOther.getEmployeeid()) || (this
.getEmployeeid() != null
&& castOther.getEmployeeid() != null && this.getEmployeeid()
.equals(castOther.getEmployeeid())))
&& ((this.getCitycode() == castOther.getCitycode()) || (this
.getCitycode() != null
&& castOther.getCitycode() != null && this
.getCitycode().equals(castOther.getCitycode())));
}

public int hashCode() {
int result = 17;

result = 37
* result
+ (getEmployeeid() == null ? 0 : this.getEmployeeid()
.hashCode());
result = 37 * result
+ (getCitycode() == null ? 0 : this.getCitycode().hashCode());
return result;
}

}

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.palmcity.model.Employeecityref" table="EMPLOYEECITYREF" schema="TRAFFICS">
<composite-id name="id" class="com.palmcity.model.EmployeecityrefId">
<key-property name="employeeid" type="java.lang.Long">
<column name="EMPLOYEEID" precision="22" scale="0" />
</key-property>
<key-property name="citycode" type="java.lang.String">
<column name="CITYCODE" length="20" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

这是类映射文件
salana 2010-06-11
  • 打赏
  • 举报
回复
尽管大家没有帮到我,但是还要谢谢大家,我解决了
是这样的:From a where a.id.citycode='11'
nxwfy 2010-06-10
  • 打赏
  • 举报
回复
为什么有两个,复合主键??
cxj61126 2010-06-10
  • 打赏
  • 举报
回复
也就是说你映射的是视图,现在用oracle可直接映射视图,不用映射多个对象那么麻烦,我就在用,不知道你用的什么数据库,其它的支持可能就要你的这种方法,要设置成序列化,复合主键
niujw002 2010-06-10
  • 打赏
  • 举报
回复
关注。
wanli209 2010-06-10
  • 打赏
  • 举报
回复
太高深了啊
salana 2010-06-10
  • 打赏
  • 举报
回复
[Quote=引用楼主 salana 的回复:]
java代码:
StringBuffer hql = new StringBuffer("SELECT t FROM Citylist t, Employeecityref e WHERE t.citycode = e.citycode and e.employeeid ='"+emp.getEmployeeid()+"'");
List<Citylist> list = getSession……
[/Quote]
报错里的citycode指的是Employeecityref里没有,而我的Employeecityref映身类是两个,一个Employeecityref.java,一个EmployeecityrefId.java,EmployeecityrefId.java里面有citycode可就是取不出来
Java技术栈 2010-06-10
  • 打赏
  • 举报
回复
org.hibernate.QueryException: could not resolve property: citycode of: com.palmcity.model.Employeecityref [SELECT t FROM com.palmcity.model.Citylist t, com.palmcity.model.Employeecityref e WHERE t.citycode = e.citycode and employeeid ='35']

很明显不能处理citycode这个属性 Citylist 这个类里面有这个属性吗

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧