0

Below is my DAO class and resources class for get single data:

public List<Lipid> getLipid(int LipidId) {
    Session session = SessionUtil.getSession();
    Query query = session.createQuery("from Lipid where LipidId = :LipidId");
    System.out.println("-----------123");
    List<Lipid> lipids = query.list();
    System.out.println("---------234");
    session.close();
    return lipids;
}

My Resources Class:

@GET
@Path("/{LipidId}")
@Produces("application/json")
public Response getLipid(@PathParam("param") int LipidId){
    LipidDAO dao = new LipidDAO();
    List lipid = dao.getLipid(LipidId);
    String json = new Gson().toJson(lipid);
    return Response.ok().entity(json.toString()).build();
}

Exception in thread "main" org.hibernate.QueryException: Named parameter [LipidId] not set at org.hibernate.query.internal.QueryParameterBindingsImpl.verifyParametersBound(QueryParameterBindingsImpl.java:234)

slavoo
  • 5,798
  • 64
  • 37
  • 39
mehul
  • 109
  • 3
  • 12

2 Answers2

0

please set value of :LipidId like this

query.setInteger("LipidId", LipidId);
Kamlesh Delat
  • 128
  • 11
  • Is It fine?? public List getLipid(int LipidId) { Session session = SessionUtil.getSession(); Query query = session.createQuery("from Lipid where LipidId = :LipidId"); System.out.println("-----------123"); query.setInteger("LipidId", LipidId); List lipids = query.list(); System.out.println("---------234"); session.close(); return lipids; } – mehul Jun 13 '17 at 10:07
  • sett the value for lipid id As show in above code. Now error is not coming bt still cannot getsingle data... m having data with a particular id m passing then also getting [ ] in browser.. Help me Out?? – mehul Jun 13 '17 at 10:15
  • please set limit https://stackoverflow.com/questions/1239723/how-do-you-do-a-limit-query-in-hql – Kamlesh Delat Jun 13 '17 at 11:17
  • Unknown parameter name : LipidId public List getLipid(int LipidId) { Session session = SessionUtil.getSession(); Transaction tx = session.beginTransaction(); Query query = session.createQuery("from Lipid where LipidId = LipidId"); query.setMaxResults(LipidId); query.setInteger("LipidId", LipidId); List lipids = query.list(); tx.commit(); session.close(); return lipids; } – mehul Jun 13 '17 at 11:30
  • query.setMaxResults(1); – Kamlesh Delat Jun 13 '17 at 11:40
  • String json = new Gson().toJson(lipid.get(0)); – Kamlesh Delat Jun 13 '17 at 11:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146527/discussion-between-kamlesh-delat-and-mree). – Kamlesh Delat Jun 13 '17 at 11:43
  • Yes. I have set maxResult as 1.. Now also error is coming... Unknown parameter name : LipidId – mehul Jun 13 '17 at 11:43
  • change "from Lipid where LipidId = LipidId to "from Lipid where LipidId = :LipidId – Kamlesh Delat Jun 13 '17 at 12:25
  • Now Wat the error m getting is: javax.servlet.ServletException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 – mehul Jun 14 '17 at 17:18
0

Please set Query parameter in query. post ur hibernateDao code here