本文整理汇总了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());
}
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}