spring - How to handle jpa entity -
would like to reclaim I have a table client and the results I used to like this
public Claintprent getClient (Long customer ID, Long parent id) {string select client CP query string = "CP where cp.cid.id =: clientId" and cp.pid.id =: parentId "; query = entityManagerUtil.getQuery (queryString); Query.setParameter ( "clientId", clientId); Query.setParameter ( "parentId", parentId); return (Claintprenent) query .getSingleResult (); It DAO method.
In fact the client is the controller class to receive the first control and then DAO class
tells people that the client table is empty so return (ClientParent) query.getSingleResult (in this case); will throw me the error. I can press and hold it to go with the service class with the controller class Try the catch block. But I want to know that I have any exceptions With I can do. I mean that I have changed the query or what should I return so that I can never throw exceptions, even if the table is empty
You can use the getResultList () method
public clientPart client (Long Client ID, Long Parent ID) {String Query String = "CP Client CP Choose where cp.cid.id =: clientId "and" cp.pid.id =: parentId "; Query Query = entityManagerUtil.getQuery (queryString); Query.setParameter ("clientId", clientId); Query.setParameter ("parentId", parentId); & Lt; ClientParent & gt; Results = query.getResultList (); If (result! = Null & amp; amp; result; size ()>); return result.get (0); } And {return tap; }}
Comments
Post a Comment