當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.getSingleResult方法代碼示例

本文整理匯總了Java中org.hibernate.Query.getSingleResult方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.getSingleResult方法的具體用法?Java Query.getSingleResult怎麽用?Java Query.getSingleResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.Query的用法示例。


在下文中一共展示了Query.getSingleResult方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserFromEmail

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized public static UserDetails getUserFromEmail(String email)
{
         UserDetails ud = null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from UserDetails ud where ud.email_id=:eid");
                qry.setParameter("eid", email);
                ud=(UserDetails)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 //ud=lst.get(0);
                 return (ud);
            }
            else
            {
                 return (new UserDetails());
            }
}
 
開發者ID:Tejas07PSK,項目名稱:EBwn2_ForOpenShift,代碼行數:38,代碼來源:Fetch.java

示例2: getPlaceFromDesc

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized public static Places getPlaceFromDesc(String desc)
{
         Places pl = null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from Places pl where pl.pl_desc=:pldesc");
                qry.setParameter("pldesc", desc);
                pl=(Places)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 return (pl);
            }
            else
            {
                 return (new Places());
            }
}
 
開發者ID:Tejas07PSK,項目名稱:EBwn2_ForOpenShift,代碼行數:37,代碼來源:Fetch.java

示例3: getUserFromId

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized public static UserDetails getUserFromId(String userid)
{
         UserDetails ud = null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
                qry.setParameter("uid", userid);
                ud=(UserDetails)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 return (ud);
            }
            else
            {
                 return (new UserDetails());
            }
}
 
開發者ID:Tejas07PSK,項目名稱:EBwn2_ForOpenShift,代碼行數:37,代碼來源:Fetch.java

示例4: getUserFromEmail

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized public static UserDetails getUserFromEmail(String email)
{
         UserDetails ud = null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from UserDetails ud where ud.email_id=:eid");
                qry.setParameter("eid", email);
                ud=(UserDetails)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            { 
                 return (ud);
            }
            else
            {
                 return (new UserDetails());
            }
}
 
開發者ID:Tejas07PSK,項目名稱:maven_EWorld_OpenShift,代碼行數:37,代碼來源:Fetch.java

示例5: getPlaceFromDesc

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized public static Places getPlaceFromDesc(String desc)
{
         Places pl = null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from Places pl where pl.pl_desc=:pldesc");
                qry.setParameter("pldesc", desc);
                pl=(Places)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 return (pl);
            }
            else
            {
                 return (new Places());
            }
}
 
開發者ID:Tejas07PSK,項目名稱:maven_EWorld_OpenShift,代碼行數:37,代碼來源:Fetch.java

示例6: setPlace

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized private static Places setPlace(String ... vals)
{
         UserDetails ud=null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
               s=sf.openSession();
               s.beginTransaction();
               Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
               qry.setParameter("uid", vals[0]);
               ud=(UserDetails)qry.getSingleResult();
               s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
                
           if(chk==0)
           {
                   Places pl=new Places ();
                   Address addr = pl.getAddr();
                   pl.setPname(vals[1]);
                   pl.setPl_type(vals[2]);
                   pl.setPl_id(generatePLACE_ID());
                   addr.setLocality(vals[3]);
                   addr.setCity(vals[4]);
                   addr.setPincode(vals[5]);
                   addr.setState(vals[6]);
                   addr.setCountry(vals[7]);
                   pl.setAddr(addr);
                   pl.setPl_desc(vals[8]);
                   pl.setUd(ud);
                   return (pl);
           }
           else
           {
                return (null);
           }
 }
 
開發者ID:Tejas07PSK,項目名稱:EBwn2_ForOpenShift,代碼行數:51,代碼來源:Insert.java

示例7: setUserRatings

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized private static ArrayList<Object> setUserRatings(String ... vals)
{
         UserDetails ud=null;
         Places pl=null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                ud=(UserDetails)qry.getSingleResult();
                qry=s.createQuery("from Places p where p.pl_id=:pid");
                qry.setParameter("pid",vals[1]);
                pl=(Places)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
                
           if(chk==0)
           {
                   UserRatings ur=new UserRatings ();
                   ur.setRat(vals[2]);
                   ur.setComm(vals[3]);
                   ur.setRat_id(generateRATE_ID());
                   ur.setPl(pl);
                   ArrayList<Object> arr=new ArrayList<Object> ();
                   arr.add(ud);
                   arr.add(ur);
                   return (arr);
           }
           else
           {
                return (null);
           }
         
}
 
開發者ID:Tejas07PSK,項目名稱:EBwn2_ForOpenShift,代碼行數:51,代碼來源:Insert.java

示例8: setPlace

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized private static Places setPlace(String ... vals)
{
         UserDetails ud=null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
               s=sf.openSession();
               s.beginTransaction();
               Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
               qry.setParameter("uid", vals[0]);
               ud=(UserDetails)qry.getSingleResult();
               s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
                
           if(chk==0)
           {
                   Places pl=new Places ();
                   Address addr = pl.getAddr();
                   pl.setPname(vals[1]);
                   pl.setPl_type(vals[2]);
                   pl.setPl_id(generatePLACE_ID());
                   addr.setLocality(vals[3]);
                   addr.setCity(vals[4]);
                   addr.setPincode(vals[5]);
                   addr.setState(vals[6]);
                   addr.setCountry(vals[7]);
                   pl.setAddr(addr);
                   pl.setPl_desc(vals[8]);
                   pl.setUd(ud);
                   return (pl);
           }
           else
           {
                return (null);
           }
 }
 
開發者ID:Tejas07PSK,項目名稱:maven_EWorld_OpenShift,代碼行數:51,代碼來源:Insert.java

示例9: setUserRatings

import org.hibernate.Query; //導入方法依賴的package包/類
synchronized private static ArrayList<Object> setUserRatings(String ... vals)
{
         UserDetails ud=null;
         Places pl=null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                ud=(UserDetails)qry.getSingleResult();
                qry=s.createQuery("from Places p where p.pl_id=:pid");
                qry.setParameter("pid",vals[1]);
                pl=(Places)qry.getSingleResult();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
                
           if(chk==0)
           {
                   UserRatings ur=new UserRatings ();
                   ur.setRat(vals[2]);
                   ur.setComm(vals[3]);
                   ur.setRat_id(generateRATE_ID());
                   ur.setPl(pl);
                   ArrayList<Object> arr=new ArrayList<Object> ();
                   arr.add(ud);
                   arr.add(ur);
                   return (arr);
           }
           else
           {
                return (null);
           }
         
}
 
開發者ID:Tejas07PSK,項目名稱:maven_EWorld_OpenShift,代碼行數:51,代碼來源:Insert.java


注:本文中的org.hibernate.Query.getSingleResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。