Named Query

NamedQuery to be added in POJO of Table

@NamedQuery(name="getEmailId",query="select lm.emailId from TblLoginMaster lm where lm.userId=:userId")
@Table(name = "tbl_LoginMaster", schema = "dbo")
public class TblLoginMaster  implements {

How to use Named Query

public List<Object> getNamedQuery(String param,Object val) {
     Query q = null;
         try {
                q = getSession().getNamedQuery("getEmailId").setInteger(param, (Integer)val); // param : userId & val : 35

         } catch (Exception e) {
        return q==null?null:q.list();
This entry was posted in Hibernate. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s