up我也正在学习hibernate;帮你顶

解决方案 »

  1.   

    你的意思是想用session.load()方法来查????
    但是因为主剑多,不知道查的是那个》???
      

  2.   

    自己搞明白了,还是谢谢各位:
    第一种方法:// query by one key and the other field ...
    public void getHoliday_HQL(String etCode,String holiday) throws Exception {
    MYSQLSessionFactory.start();
    Session session =DB2SessionFactory.currentSession() ;
    Transaction tx = session.beginTransaction();
    try {
    Holiday hld=new Holiday() ;
    StringBuffer strHQL = new StringBuffer("")
    .append("FROM                  ")
    .append("    Holiday AS hld    ")
    .append("WHERE                 ")
    .append("    hld.comp_id.etCode = ? ")
    .append("  and                  ")
    .append("    hld.activeFlag = ? ") ;
    Type type1 = Hibernate.STRING;
    Type type2 = Hibernate.INTEGER;
    Type[] type = {type1,type2 };
    Object[] args  = {etCode , new Integer(BoolEnum.BOOL_YES.getValue()) };
    List list = session.find(strHQL.toString(), args, type);
    for (Iterator iter = list.iterator(); iter.hasNext();) {
    Holiday element = (Holiday) iter.next();
    System.out.println("Holiday:    "+element.getComp_id().getHoliday()) ; 
    System.out.println("MarketCode: "+element.getComp_id().getMarketCode()) ;
    }
    tx.commit();
    } catch (Exception e) {
    if (tx != null) tx.rollback();
    System.out.println("Create Holiday Error :"+ e.toString()) ;
    } finally {
    MYSQLSessionFactory.end();
    }
    }
      

  3.   

    第二种,也是简单的那种。// Just query by the key-values..
    public void getHoliday_Key(String etCode,String holiday) throws Exception {
    MYSQLSessionFactory.start();
    Session session =DB2SessionFactory.currentSession() ;
    Transaction tx = session.beginTransaction();
    try {
    HolidayPK hldPK=new HolidayPK(etCode,holiday) ; // Create a PK Bean .
    Holiday hld =(Holiday)session.load(Holiday.class,hldPK);
    System.out.println("Holiday:    "+hld.getComp_id().getHoliday()) ; 
    System.out.println("MarketCode: "+hld.getComp_id().getMarketCode()) ;
    System.out.println("GetInputDate :    "+hld.getInputDate()) ;
    System.out.println("GetUpdateDate:    "+hld.getUpdateDate()) ;
    tx.commit();
    } catch (Exception e) {
    if (tx != null) tx.rollback();
    System.out.println("Create Holiday Error :"+ e.toString()) ;
    } finally {
    MYSQLSessionFactory.end();
    }
    }
      

  4.   

    Session session =DB2SessionFactory.currentSession
    我怎么看不懂啊