Java Code Examples for org.hibernate.Query.getSingleResult()

The following are Jave code examples for showing how to use getSingleResult() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EBwn2_ForOpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 2
Project: EBwn2_ForOpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 3
Project: EBwn2_ForOpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 4
Project: maven_EWorld_OpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 5
Project: maven_EWorld_OpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 6
Project: maven_EWorld_OpenShift   File: Fetch.java   Source Code and License Vote up 5 votes
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());
            }
}
 
Example 7
Project: EBwn2_ForOpenShift   File: Insert.java   Source Code and License Vote up 4 votes
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);
           }
 }
 
Example 8
Project: EBwn2_ForOpenShift   File: Insert.java   Source Code and License Vote up 4 votes
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);
           }
         
}
 
Example 9
Project: maven_EWorld_OpenShift   File: Insert.java   Source Code and License Vote up 4 votes
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);
           }
 }
 
Example 10
Project: maven_EWorld_OpenShift   File: Insert.java   Source Code and License Vote up 4 votes
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);
           }
         
}