Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. Query q = ssn.createSQLQuery("{ ? = call SEARCH_RESULT(?,?,?) }");
  2.  
  3. int idx = 0;
  4. q.setParameter(idx, sc.getId(), StandardBasicTypes.INTEGER);
  5. q.setString(++idx, sc.getNum() == null ? null : sc.getNum()
  6. .toString()); // second parameter
  7. q.setString(++idx, sc.getName());
  8. List list = q.list();
  9.  
  10. com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 4.
  11. com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
  12. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:262)
  13. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:221)
  14. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:598)
  15. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:386)
  16. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
  17. com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
  18. com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
  19. com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
  20. com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
  21. com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
  22. org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
  23. org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
  24. org.hibernate.loader.Loader.doQuery(Loader.java:802)
  25. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
  26. org.hibernate.loader.Loader.doList(Loader.java:2533)
  27. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
  28. org.hibernate.loader.Loader.list(Loader.java:2271)
  29. org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
  30. org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
  31. org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
  32. org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
  33.  
  34. Query q = ssn.createSQLQuery("{ ? = call SEARCH_RESULT(?,?,?) }");
  35.  
  36. { call my_function(:param1, :param2) }
  37.  
  38. return_code = 404, message = "Page not found"
  39.  
  40. return_code = 200, message = "OK"
  41.  
  42. @NamedNativeQueries({
  43. @NamedNativeQuery(name = "myFunction",
  44. query = "{ call my_function(:param1, :param2) }",
  45. resultClass = StoredProc.class)
  46. })
  47. @Entity
  48. public class StoredProc implements Serializable {
  49.  
  50. private Integer returnCode;
  51. private String message;
  52.  
  53. @Id
  54. @GeneratedValue(strategy = GenerationType.IDENTITY)
  55. @Column(name = "return_code", nullable = false, unique = true)
  56. public Integer getReturnCode() {
  57. return returnCode;
  58. }
  59. public void setReturnCode(Integer returnCode) {
  60. this.returnCode = returnCode;
  61. }
  62.  
  63. @Column(name = "message")
  64. public String getMessage() {
  65. return message;
  66. }
  67. public void setMessage(String message) {
  68. this.message = message;
  69. }
  70.  
  71. }
  72.  
  73. (StoredProc) getSession().getNamedQuery("myFunction")
  74. .setParameter("param1", value)
  75. .setParameter("param2", value2)
  76. .uniqueResult();
Add Comment
Please, Sign In to add comment