Named Query

NamedQuery to be added in POJO of Table

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

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) {
             e.printStackTrace();
    }
        return q==null?null:q.list();
    }
Advertisements
This entry was posted in Hibernate. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s