Java hibernate使用不同的标准进行连接';行不通

Java hibernate使用不同的标准进行连接';行不通,java,hibernate,Java,Hibernate,当我运行时,我得到了预期实际查询的结果查询 实际查询(待生成、期望查询) 不同的[ID] select distinct rc.* from ratecodeparam rcp , ratecodes rc where rc.travelfrom <= '2011-04-22' and rc.travelto >= '2011-04-25' and rc.id = rcp.p_id; RateCode.hbm.xml <class catalog="hermes" name=

当我运行时,我得到了预期实际查询的结果查询

实际查询(待生成、期望查询) 不同的[ID]

select distinct rc.* from ratecodeparam rcp , ratecodes rc where rc.travelfrom <= '2011-04-22' and rc.travelto >= '2011-04-25' and rc.id = rcp.p_id;
RateCode.hbm.xml

<class catalog="hermes" name="com.RateCode"  table="ratecodes">
        <id name="rateCodeId" type="java.lang.Integer">
            <column name="id"/>
            <generator class="native"/>
        </id>
        <property name="code" type="string">
            <column length="32" name="code" unique="true"/>
        </property>
        <set name="rateCodeParams" cascade="all, delete-orphan" order-by="param">
            <key>
                <column name="p_id"  />
            </key>
            <one-to-many class="com.RateCodeParam" />
         </set>
</class>

RateCodeParam.hbm.xml

<class catalog="hermes" name="com.RateCodeParam" table="ratecodeparam">
        <id name="id" type="java.lang.Integer">
            <column name="id"/>
            <generator class="identity"/>
        </id>       
        <many-to-one  class="com.RateCode" name="rateCode" insert="false" fetch="join" update="false" > 
            <column name="p_id" />
        </many-to-one>
</class>

您的查询缺少联接,因为您没有向查询中添加联接。设置fetch模式(setFetchMode)只会向现有联接添加更多详细信息。但在您的查询中,它并不存在

正确的查询可能如下所示:

Criteria crit = session.createCriteria(RateCode.class)
    .add(Restrictions.le("travelFrom", from.getTime()))
    .createCriteria("rateCodeParams", "rcp");
list = crit.list();

那么你的问题是什么呢?我的问题是,当我运行我得到的结果查询时,我期望实际的查询请编辑你的帖子并将你的问题放在那里(不仅仅是在备注中)。thanx我在这里通过谷歌得到了相同的代码,但是(选择distinct rc.*)对于distinct rc.*crit.setProjection(Projections.distinct(Projections.property(“rc.*))但是如何为RateCode.classAlias指定别名RateCode:Criteria crit=session.createCriteria(RateCode.class,“rc”);
<class catalog="hermes" name="com.RateCodeParam" table="ratecodeparam">
        <id name="id" type="java.lang.Integer">
            <column name="id"/>
            <generator class="identity"/>
        </id>       
        <many-to-one  class="com.RateCode" name="rateCode" insert="false" fetch="join" update="false" > 
            <column name="p_id" />
        </many-to-one>
</class>
Criteria crit = session.createCriteria(RateCode.class)
    .add(Restrictions.le("travelFrom", from.getTime()))
    .createCriteria("rateCodeParams", "rcp");
list = crit.list();