我有一个sql
查询。任何人都可以转换为休眠标准吗?
SELECT TH_ID,TH_NAME FROM t_o2_th_master WHERE TH_ID IN(SELECT TH_ID FROM t_o2_user_gameplay WHERE USER_ID=10010 AND STATUS_TYPE_CODE_ID=1303)
这是字段名称的实体类:
SELECT treasureHuntId,treasureHuntName FROM TreasureHuntMasterEntity WHERE treasureHuntId IN(SELECT treasureHuntId FROM UserGamePlayEntity WHERE userId:userID AND statusTypeCodeId:statusTypeCodeID)
答案 0 :(得分:0)
我们可以使用hibernate直接运行SQL查询。 Hibernate提供了两种不同类型的查询
答案 1 :(得分:0)
变化
WHERE userId:userID
到
WHERE userId = :userID
答案 2 :(得分:0)
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.openSession();
Criteria criteria =session.createCriteria( t_o2_th_master.class );
criteria.createCriteria( "t_o2_user_gameplay", "user" );
criteria.add( Restrictions.eq( "user.userId", 10010 ) );
criteria.add( Restrictions.eq( "user.statusTypeId", 1303 ) );
t_o2_th_master masterList = criteria.list();
t_o2_th_master master=null;
if(masterList.size()>0){
master=masterList.get(0);
}