日期:2014-05-20  浏览次数:20769 次

急求解答ssh问题(多对多)
Configuration cfg = new Configuration().configure();
Session session = cfg.buildSessionFactory().openSession();
Query query = session.createQuery("from SysUser s where s.userName='admin'");
此方法可以得到SysUser方的数据和关联的另一方数据
当在ssh下 List list=(List)getHibernateTemplate().find(" from SysUser where userName='amdin'");
只能得到SysUser的数据但是得不到关联的另一方的数据
配置文件如下SysUser:
<?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">
   
<hibernate-mapping>
<!-- 
  Created by the Middlegen Hibernate plugin 2.1

  http://boss.bekk.no/boss/middlegen/
  http://www.hibernate.org/
-->

<class 
  name="com.lingxun.hibernate.SysUser" 
  table="sys_user"
>
  <meta attribute="class-description" inherit="false">
  @hibernate.class
  table="sys_user"
  </meta>
  <meta attribute="implement-equals" inherit="false">true</meta>

  <id
  name="id"
  type="java.lang.Integer"
  column="id"
  >
  <meta attribute="field-description">
  @hibernate.id
  generator-class="native"
  type="java.lang.Integer"
  column="id"

  </meta>
  <meta attribute="use-in-equals">true</meta>
  <generator class="native" />
  </id>

  <property
  name="userName"
  type="java.lang.String"
  column="user_name"
  not-null="true"
  unique="true"
  length="20"
  >
  <meta attribute="use-in-tostring">true</meta>
  <meta attribute="use-in-equals">true</meta>
  <meta attribute="field-description">
  @hibernate.property
  column="user_name"
  unique="true"
  length="20"
  not-null="true"
  </meta>  
  </property>
  <property
  name="realName"
  type="java.lang.String"
  column="real_name"
  not-null="false"
  length="20"
  >
  <meta attribute="use-in-tostring">true</meta>
  <meta attribute="use-in-equals">true</meta>
  <meta attribute="field-description">
  @hibernate.property
  column="real_name"
  length="20"
  not-null="true"
  </meta>  
  </property>
  <property
  name="phone"
  type="java.lang.String"
  column="phone"
  not-null="true"
  length="20"
  >
  <meta attribute="use-in-tostring">true</meta>