配置文件如下
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
  <class entity-name="SF_ORGANIZATION" table="SF_ORGANIZATION">
    <id name="ID" type="string">
      <column name="ID" length="32"/>
      <generator class="assigned"/>
    </id>
    <property name="ORG_CODE" type="string">
      <column name="ORG_CODE" length="40"/>
    </property>
    <property name="ORG_NAME" type="string">
      <column name="ORG_NAME" length="100"/>
    </property>
    <property name="PARENT_ID" type="string">
      <column name="PARENT_ID" length="32"/>
    </property>
    <property name="CORP_ID" type="string">
      <column name="CORP_ID" length="32"/>
    </property>
    <property name="ORG_TYPE" type="string">
      <column name="ORG_TYPE" length="2"/>
    </property>
    <property name="TS" type="string">
      <column name="TS" length="19"/>
    </property>
    <property name="IS_USE" type="string">
      <column name="IS_USE" length="1"/>
    </property>    <bag name="models"
       cascade="all"
       inverse="true">
      <key column="ORG_ID"/>
      <one-to-many class="SF_USER"/>
     </bag>
  </class>
  
</hibernate-mapping>代码
String hql = "select new map(u.ID as ID) from SF_ORGANIZATION o right join SF_USER  u  where o.ID = u.ORG_ID";
List ls = commonDao.queryList(hql);
执行结果如下
2008-04-08 16:50:10,281 ERROR [org.hibernate.hql.PARSER] -  Path expected for join!
2008-04-08 16:50:10,328 ERROR [org.hibernate.hql.PARSER] -  Invalid path: 'u.ID'
2008-04-08 16:50:10,328 ERROR [org.hibernate.hql.PARSER] - <AST>:0:0: unexpected end of subtree
[16:50:10.328] org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
[16:50:10.328] Caused by: java.lang.NullPointerException
[16:50:10.328]  at org.hibernate.hql.ast.HqlSqlWalker.setAlias(HqlSqlWalker.java:851)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.aliasedSelectExpr(HqlSqlBaseWalker.java:2069)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.constructor(HqlSqlBaseWalker.java:2226)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1952)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1825)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1394)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
[16:50:10.328]  at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
[16:50:10.328]  at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
[16:50:10.328]  at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
[16:50:10.328]  at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
[16:50:10.328]  at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
[16:50:10.328]  at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
[16:50:10.328]  at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
[16:50:10.328]  at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
[16:50:10.328]  at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
[16:50:10.328]  at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
[16:50:10.328]  at bc.sf.dao.CommonDao$8.doInHibernate(CommonDao.java:188)
[16:50:10.328]  at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
[16:50:10.328]  at bc.sf.dao.CommonDao.queryList(CommonDao.java:185)
[16:50:10.328]  at bc.sf.dao.CommonDao.queryList(CommonDao.java:164)
[16:50:10.328]  at bc.sf.ctl.WfController.handleRequestInternal(WfController.java:53)
[16:50:10.328]  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
[16:50:10.328]  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
[16:50:10.328]  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
[16:50:10.328]  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
[16:50:10.328]  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:461)
[16:50:10.328]  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:426)
[16:50:10.328]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
[16:50:10.328]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
[16:50:10.328]  at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
[16:50:10.328]  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
[16:50:10.328]  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
[16:50:10.328]  at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:70)
[16:50:10.328]  at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173)
[16:50:10.328]  at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
[16:50:10.328]  at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274)
[16:50:10.328]  at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)
[16:50:10.328]  at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:520)
[16:50:10.328]  at com.caucho.util.ThreadPool.run(ThreadPool.java:442)
[16:50:10.328]  at java.lang.Thread.run(Thread.java:595)

解决方案 »

  1.   

    String hql = "select new map(u.ID as ID) from SF_ORGANIZATION o right join o.SF_USER  u  where o.ID = u.ORG_ID"; 
    List ls = commonDao.queryList(hql); 
      

  2.   

    String hql = "select new map(u.ID as ID) from SF_ORGANIZATION o right join o.SF_USER  u  where o.ID = u.ORG_ID";  
    List ls = commonDao.queryList(hql); 红色的好像不用的,我加上去 会出错, hibernate 会自动 join on~~ 
      

  3.   

    去掉了也不行
    另一个配置文件,不知道是否正确
    <?xml version="1.0" encoding="GBK"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
      <class entity-name="SF_USER" table="SF_USER">
        <id name="ID" type="string">
          <column name="ID" length="32"/>
          <generator class="assigned"/>
        </id>
        <property name="ORG_ID" type="string">
          <column name="ORG_ID" length="32"/>
        </property>
        <property name="USER_CODE" type="string">
          <column name="USER_CODE" length="20"/>
        </property>
        <property name="USER_PWD" type="string">
          <column name="USER_PWD" length="20"/>
        </property>
        <property name="USER_NAME" type="string">
          <column name="USER_NAME" length="40"/>
        </property>
        <property name="AUTH_TYPE" type="string">
          <column name="AUTH_TYPE" length="1"/>
        </property>
        <property name="ENABLE_DATE" type="string">
          <column name="ENABLE_DATE" length="10"/>
        </property>
        <property name="DISABLE_DATE" type="string">
          <column name="DISABLE_DATE" length="10"/>
        </property>
        <property name="TS" type="string">
          <column name="TS" length="19"/>
        </property>
        <property name="DS" type="string">
          <column name="DS" length="1"/>
        </property>
        <property name="ORG_CODE" type="string">
          <column name="ORG_CODE" length="100" not-null="false"/>
        </property>
      </class>
    </hibernate-mapping>
      

  4.   

    SF_USER  前面加 o. 没有?要指定关联的 对象前缀