title: how to use hibernate hql to select datas in two tables?
body: <p>my code like like this:
  I want to select data in two tables</p>
  
  <pre><code>    // ArrayList&lt;DetailType&gt; list = null;
      SessionFactory sf = null;
      Session ses = null;
      try {
  
          Configuration cfg = new Configuration().configure();
          ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(
                  cfg.getProperties()).buildServiceRegistry();
          sf = cfg.buildSessionFactory(sr);
          ses = sf.openSession();
          // 执行查询语句
  
          String hql = "select new DetailVoMain(d.d_id,d.d_name,m.m_name)"
                  + "from MainType m, DetailType d "
                  + "where d.d_main_id = m.m_id";
          Query query = ses.createQuery(hql);
  
          List&lt;?&gt; list = query.list();
          for (int i = 0; i &lt; list.size(); i++) {
              DetailVoMain detailType = (DetailVoMain) list.get(i);
              System.out.println("dId--------&gt;" + detailType.getdId());
              System.out.println("dNam--------&gt;" + detailType.getdName());
              System.out.println("mNam--------&gt;" + detailType.getmName());
          }
      } catch (HibernateException e) {
          System.out.println("hibernate exception");
          e.printStackTrace();
  
      } finally {
          ses.close();
          sf.close();
      }
  </code></pre>
  
  <p>and myeclipese give me the error message:</p>
  
  <pre><code>hibernate exception
  </code></pre>
  
  <p>org.hibernate.QueryException: could not resolve property: d_id of: com.xunfang.em_mallServer.bean.DetailType [select new DetailVoMain(d.d_id,d.d_name,m.m_name)from com.xunfang.em_mallServer.bean.MainType m, com.xunfang.em_mallServer.bean.DetailType d where d.d_main_id = m.m_id]
      at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)
      at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)
      at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1968)
      at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:313)
      at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:490)
      at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:616)
      at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:267)
      at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:214)
      at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:119)
      at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:115)
      at org.hibernate.hql.internal.ast.tree.DotNode.resolveSelectExpression(DotNode.java:678)
      at org.hibernate.hql.internal.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:893)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2208)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.constructor(HqlSqlBaseWalker.java:2502)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2275)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2145)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1451)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:249)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:184)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:137)
      at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105)
      at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
      at com.xunfang.em_mallServer.util.Test.main(Test.java:39)</p>
  
  <p>please help me,i test all the night!</p>
  
  <p>my MainType entity like this:</p>
  
  <pre><code>public class MainType {
  private String mId; // 编号
  private String mName; // 类别名称
  
  public String getmId() {
      return mId;
  }
  
  public void setmId(String mId) {
      this.mId = mId;
  }
  
  public String getmName() {
      return mName;
  }
  </code></pre>
  
  <p>and mapping like this:</p>
  
  <pre><code>&lt;hibernate-mapping package="com.xunfang.em_mallServer.bean"&gt;
  
  &lt;class name="MainType" table="t_main_type"&gt; &lt;!-- 设置表名和字段对应数据 --&gt;
      &lt;id name="mId" column="m_id" type="string"&gt;
  
      &lt;/id&gt;
      &lt;property name="mName" column="m_name" type="string"&gt;&lt;/property&gt;
  
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>DetailType entity like this:</p>
  
  <pre><code>public class DetailType {
  /**
   * 小类编号
   */
  private String dId;
  /**
   * 小类名称
   */
  private String dName;
  /**
   * 归属大类编号
   */
  private String dMainId;
  
  public String getdId() {
      return dId;
  }
  
  public void setdId(String dId) {
      this.dId = dId;
  }
  
  public String getdName() {
      return dName;
  }
  
  public void setdName(String dName) {
      this.dName = dName;
  }
  
  public String getdMainId() {
      return dMainId;
  }
  
  public void setdMainId(String dMainId) {
      this.dMainId = dMainId;
  }
  </code></pre>
  
  <p>and the mapping:</p>
  
  <pre><code>&lt;hibernate-mapping package="com.xunfang.em_mallServer.bean"&gt;
  
  &lt;class name="DetailType" table="t_detail_type"&gt; &lt;!-- 设置表名和字段对应数据 --&gt;
      &lt;id name="dId" column="d_id" type="string"&gt;
  
      &lt;/id&gt;
      &lt;property name="dName" column="d_name" type="string"&gt;&lt;/property&gt;
      &lt;property name="dMainId" column="d_main_id" type="string"&gt;&lt;/property&gt;
  
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>thank you for help me!</p>