hibernate没有映射bean,返回Object List

时间:2010-10-11 15:37:54

标签: java hibernate orm hql

喜 我是新人,冬眠让我疯狂全职。 我hv 2表一对二映射。当我只加入这两个这两个,那么hibernate不是映射,当我将table1与其他table3连接时,它给我精细的映射结果。

Bean1

private int id ;
private BlessUser blessUser ;
private SnsAuthenticator snsAuth ;
public void setSnsAuth(SnsAuthenticator snsAuth) {
    snsAuth.setSnsUserId(getId());
    this.snsAuth = snsAuth;
}

HBM文件

<one-to-one name="snsAuth" class="com.utilami.model.SnsAuthenticator" property-ref="snsUserId"
  cascade="all"></one-to-one>

Bean2

private int id;
private int snsUserId;
private String key;
private String value;

HBM文件 正常的...     

执行lik:

    Session session = Utility.getSessionFactory().openSession();
    Query query = session.createQuery("from SnsUser su join su.snsAuth sa where su.blessUserId =1");
    List list = query.list();

此查询正常

String query = "from BlessUser bu join fetch bu.snsUser su where bu.id = su.blessUserId and bu." + "UserName" + " = " + "'qw'";
非常感谢提前。 THX

1 个答案:

答案 0 :(得分:0)

from SnsUser su join fetch su.snsAuth sa where su.blessUserId = :id

缺少fetch关键字。