Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Query q = ssn.createSQLQuery("{ ? = call SEARCH_RESULT(?,?,?) }");
- int idx = 0;
- q.setParameter(idx, sc.getId(), StandardBasicTypes.INTEGER);
- q.setString(++idx, sc.getNum() == null ? null : sc.getNum()
- .toString()); // second parameter
- q.setString(++idx, sc.getName());
- List list = q.list();
- com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 4.
- com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:262)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:221)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:598)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:386)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
- com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
- com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
- com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
- com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
- com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
- org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
- org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
- org.hibernate.loader.Loader.doQuery(Loader.java:802)
- org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
- org.hibernate.loader.Loader.doList(Loader.java:2533)
- org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
- org.hibernate.loader.Loader.list(Loader.java:2271)
- org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
- org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
- org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
- org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
- Query q = ssn.createSQLQuery("{ ? = call SEARCH_RESULT(?,?,?) }");
- { call my_function(:param1, :param2) }
- return_code = 404, message = "Page not found"
- return_code = 200, message = "OK"
- @NamedNativeQueries({
- @NamedNativeQuery(name = "myFunction",
- query = "{ call my_function(:param1, :param2) }",
- resultClass = StoredProc.class)
- })
- @Entity
- public class StoredProc implements Serializable {
- private Integer returnCode;
- private String message;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "return_code", nullable = false, unique = true)
- public Integer getReturnCode() {
- return returnCode;
- }
- public void setReturnCode(Integer returnCode) {
- this.returnCode = returnCode;
- }
- @Column(name = "message")
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- }
- (StoredProc) getSession().getNamedQuery("myFunction")
- .setParameter("param1", value)
- .setParameter("param2", value2)
- .uniqueResult();
Add Comment
Please, Sign In to add comment