hql联合查询两张表,最后合并重复的列(p.cname,c.cname) 5
下面这条hql语句好像不对,怎么该啊?Stringhql="fromPersonMsgsp,ClassMsgcwherep.cname=c.cnameandc.cname...
下面这条hql语句好像不对,怎么该啊?
String hql = "from PersonMsgs p,ClassMsg c where p.cname=c.cname and c.cname="+personmsgs.getClassmsg().getCname();
下面是各个文件
public class PersonMsgs implements java.io.Serializable {
private Integer personId;
private String pname;
private Integer hight;
private Integer weight;
private ClassMsg classmsg;
private String photo;
//getters,setters,constructers
}
public class ClassMsg implements java.io.Serializable {
private Integer cname;
private String gmsg;
private String mteachername;
//getters,setters,constructers
}
PersonMsgs与ClassMsg是多对一
ClassMsg.hbm.xml 文件
<hibernate-mapping>
<class name="org.model.ClassMsg" table="classmsg" catalog="renshiguanli">
<id name="cname" type="java.lang.Integer">
<column name="cname" />
<generator class="native"></generator>
</id>
<property name="gmsg" type="java.lang.String">
<column name="gmsg" length="45" not-null="true" />
</property>
<property name="mteachername" type="java.lang.String">
<column name="mteachername" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
PersonMsgs.hbm.xml 文件
<hibernate-mapping>
<class name="org.model.PersonMsgs" table="personsmsg" catalog="renshiguanli">
<id name="personId" type="java.lang.Integer">
<column name="personId"/>
<generator class="identity"></generator>
</id>
<property name="pname" type="java.lang.String">
<column name="pname" length="45" not-null="true" />
</property>
<property name="hight" type="java.lang.Integer">
<column name="hight" />
</property>
<property name="weight" type="java.lang.Integer">
<column name="weight" />
</property>
<property name="photo" type="java.lang.String">
<column name="photo"/>
</property>
<many-to-one name="classmsg" column="cname" cascade="all"></many-to-one>
</class>
</hibernate-mapping> 展开
String hql = "from PersonMsgs p,ClassMsg c where p.cname=c.cname and c.cname="+personmsgs.getClassmsg().getCname();
下面是各个文件
public class PersonMsgs implements java.io.Serializable {
private Integer personId;
private String pname;
private Integer hight;
private Integer weight;
private ClassMsg classmsg;
private String photo;
//getters,setters,constructers
}
public class ClassMsg implements java.io.Serializable {
private Integer cname;
private String gmsg;
private String mteachername;
//getters,setters,constructers
}
PersonMsgs与ClassMsg是多对一
ClassMsg.hbm.xml 文件
<hibernate-mapping>
<class name="org.model.ClassMsg" table="classmsg" catalog="renshiguanli">
<id name="cname" type="java.lang.Integer">
<column name="cname" />
<generator class="native"></generator>
</id>
<property name="gmsg" type="java.lang.String">
<column name="gmsg" length="45" not-null="true" />
</property>
<property name="mteachername" type="java.lang.String">
<column name="mteachername" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
PersonMsgs.hbm.xml 文件
<hibernate-mapping>
<class name="org.model.PersonMsgs" table="personsmsg" catalog="renshiguanli">
<id name="personId" type="java.lang.Integer">
<column name="personId"/>
<generator class="identity"></generator>
</id>
<property name="pname" type="java.lang.String">
<column name="pname" length="45" not-null="true" />
</property>
<property name="hight" type="java.lang.Integer">
<column name="hight" />
</property>
<property name="weight" type="java.lang.Integer">
<column name="weight" />
</property>
<property name="photo" type="java.lang.String">
<column name="photo"/>
</property>
<many-to-one name="classmsg" column="cname" cascade="all"></many-to-one>
</class>
</hibernate-mapping> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询