hibernate 联合主键查询

@SuppressWarnings("unchecked")
  public Xs_xjydsqb queryByID(XjydsqId xjydsqId){
   
//   Xs_xjydsqb xsXjydsqb = new Xs_xjydsqb(); 
//   xsXjydsqb.setXjydsqId(xjydsqId);
//   List queryByObject = queryByObject(xsXjydsqb);
//   System.out.println(queryByObject);
//   System.out.println(queryByObject.size());
//   
//   
//   Session session = getSession();
//   Xs_xjydsqb xjydsqb = (Xs_xjydsqb)session.get(Xs_xjydsqb.class, xjydsqId);
//   Xs_xjydsqb xjydsqb2 = (Xs_xjydsqb)session.load(Xs_xjydsqb.class, xjydsqId);
//   System.out.println(xjydsqb);
//   System.out.println(xjydsqb2);
//   return null;
   
  
   Session session = getSession();
   Query query = session.createQuery("from Xs_xjydsqb t where t.xjydsqId.sqbh="+xjydsqId.getSqbh());
   List list = query.list();
   Xs_xjydsqb xjydsqb =(Xs_xjydsqb) list.get(0);
 
   return xjydsqb;


  }


其中第一个方法最终没能成行,主要是cglib与hibernate整合的jar包出现兼容问题
第二种是可行的,而且可以完善主键的条件.

你可能感兴趣的:(hibernate 联合主键查询)