2012-10-21 175 views
-2

我的項目是java ee web應用程序我使用hibernate,因爲我想搜索符合item_id的值,所以我編寫了搜索結果的代碼,但搜索值沒有顯示,所以如何解決此問題請幫助我。如何檢索搜索結果?

 if(submitType != null && item_id != null) 
    { 


    try { 
     AssetsObject assets = new AssetsObject(); 

     assets.setItem_id(item_id); 

     AssetsObject assets1 =assetsProvider.getAssets(assets); 






       item_name= assets1.getItem_name(); 

       hardware = assets1.getHardware(); 

       software = assets1.getSoftware(); 

       vender = assets1.getVender(); 

       venderTel = assets1.getVenderTel(); 

       venderaddress= assets1.getVenderaddress(); 


       return INPUT; 


       } 
     catch (Exception e) 
     { 
     addActionError("Not vailed item No or its not in the database"); 
         //return INPUT; 
     } 

我的implimenter類查詢是這個我覺得這個類的問題,你能解決這個問題嗎?

公共類AssetsProviderImpl實現AssetsProvider { 受保護的靜態記錄儀日誌= Logger.getLogger(AssetsProviderImpl.class .getName());

 private HibernateProvider hibernateProvider; 

     public AssetsProviderImpl(HibernateProvider hibernateProvider) throws ProviderException 
     { 
      this.hibernateProvider = hibernateProvider; 

      log.info("AssetsProviderImpl created"); 
     } 

     public AssetsObject insertAssets(AssetsObject assets) throws ProviderException 
     { 


      return (AssetsObject) hibernateProvider.save(assets); 


     } 

     public AssetsObject getAssets(AssetsObject assets) throws ProviderException 
     { 
      try 
      { 
       Session session = hibernateProvider.openSession();   

       try 
       {    

        Query query = (Query) session.createQuery("from org.efs.openreports.objects.AssetsObject as assets " 
           + "where assets.item_id = ?"); 
        List list1 = (List) ((org.hibernate.Query) query).list(); 

        AssetsObject as = (AssetsObject) list1; 

        return as; 
       } 
       catch (HibernateException he) 
       {    
        throw he; 
       } 
       finally 
       { 
        session.close(); 
       } 
      } 
      catch (HibernateException he) 
      { 
       throw new ProviderException(he); 
      } 
     } 

>

回答

1

你不指定您getAssets(assets)方法的任何變量的結果。我不明白任何人如何顯示結果。我猜的代碼應該是:

AssetsObject assets1 = assetsProvider.getAssets(assets); 

不要把它壞,但Java EE和Hibernate的是複雜的野獸,看着你的代碼,好像你真的不掌握一些基本的Java的東西比如調用一個方法並分配它的結果。您也不尊重Java命名約定。你不應該花一些時間先學習基本的東西嗎?

+0

thanx我應該學習,我編輯這個,但不顯示結果你能修復我的impliment查詢。 – user1763298