表格中定义的外键那一列怎样采用HQL语句显示出来.

08-04-30 algz

A表格:
<many-to-one name="member" class="com.common.hibernate.member.Member" fetch="select">
<column name="author" length="10" not-null="true" />
</many-to-one>
HQL:
select member from A表 as model

报错:
javax.servlet.ServletException: unexpected token: member
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)


root cause

line 1:8: unexpected token: member
org.hibernate.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:1330)
org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1106)
org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)
org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
org.hibernate.engine.query.HQLQueryPlan. <init>(HQLQueryPlan.java:75)
org.hibernate.engine.query.HQLQueryPlan. <init>(HQLQueryPlan.java:54)

xyz
2008-04-30 10:59

select model.member from A表格 as model

algz
2008-04-30 11:21

不行,依然报错.
具体问题:

主表:
<class name="com.common.hibernate.member.Member" table="member" catalog="firstbbs">
<id name="idmember" type="java.lang.Integer">
<column name="idmember" />
<generator class="native"></generator>
</id>
<property name="username" type="java.lang.String">
<column name="username" length="10" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="10" />
</property>
星光风@守护(26264060) 10:50:28
从表:
<class name="com.common.hibernate.doc.Doc" table="doc" catalog="firstbbs">
<id name="iddoc" type="java.lang.Integer">
<column name="iddoc" />
<generator class="native"></generator>
</id>
<many-to-one name="member" class="com.common.hibernate.member.Member" fetch="select">
<column name="author" length="10" not-null="true" />
</many-to-one>
星光风@守护(26264060) 10:51:09
public class Doc implements java.io.Serializable {

// Fields

private Integer iddoc;
private Member member;
public Integer getIddoc() {
return this.iddoc;
}

public void setIddoc(Integer iddoc) {
this.iddoc = iddoc;
}

public Member getMember() {
return this.member;
}

public void setMember(Member member) {
this.member = member;
}
星光风@守护(26264060) 10:51:58
DAO:
String queryString = "from Doc as model , Member List tem= getHibernateTemplate().find(queryString); return tem;

xyz
2008-04-30 12:41

呵呵,你既然有hibernate了,为什么会有'主表','从表'的概念?

algz
2008-04-30 12:53

数据库中难道没有主从表?