开发者

hibernate not mapping the bean, returning Object List

开发者 https://www.devze.com 2023-01-19 07:37 出处:网络
hi am new and hibernate is driving me crazy full time. i hv 2 tables one-2-one mapping. when i join only these 2 these two then hibernate is not mapping and when i join table1 with some other table3

hi am new and hibernate is driving me crazy full time. i hv 2 tables one-2-one mapping. when i join only these 2 these two then hibernate is not mapping and when i join table1 with some other table3 then its giving me fine mapped results.

Bean1

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

HBM file

<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 file normal hbm...

Executing 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();

This query works fine

String query = "from BlessUser bu join fetch bu.snsUser su where bu.id = su.blessUserId and bu." + "UserName" + " = " + "'qw'";

many thanks in advance. thx


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

The fetch keyword was missing.

0

精彩评论

暂无评论...
验证码 换一张
取 消