I ma trying to get a function call that returns the following
ALTER FUNCTION dwf_daily_site_gross_sales_by_revclass
(
@dtstart_time datetime,
@dtend_time datetime
)
RETURNS @result TABLE (
rev_class_gross_id integer,
rev_class_name nvarchar(50),
rev_class_gross_amount money
)
However I get this error
16:16:09,586 DEBUG JDBCContext:214 - after transaction begin
16:16:09,586 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [createSQLQuery] to proceed to real session
16:16:09,586 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [getNamedQuery] to proceed to real session
query={ ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }
16:16:09,588 DEBUG QueryPlanCache:118 - located native-sql query plan in cache ({ ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) })
16:16:09,589 DEBUG SessionImpl:1685 - SQL query: { ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }
16:16:09,590 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:16:09,590 DEBUG SQL:401 - { ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }
Hibernate: { ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }
16:16:09,591 DEBUG AbstractBatcher:484 - preparing statement
16:16:09,607 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:16:09,607 DEBUG AbstractBatcher:533 - closing statement
16:16:09,610 DEBUG JDBCExceptionReporter:69 - could not execute query [{ ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }]
com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 3.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
at org.hibernate.dialect.SybaseDialect.getResultSet(SybaseDialect.java:186)
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:193)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1784)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at dwbridge.testdb.selectGross(testdb.java:94)
at dwbridge.testdb.main(testdb.java:24)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 3.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(Unknown Source)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
at org.hibernate.dialect.SybaseDialect.getResultSet(SybaseDialect.java:186)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:193)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1784)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 8 more
at dwbridge.testdb.selectGross(testdb.java:94)
at dwbridge.testdb.main(testdb.java:24)
16:16:09,613 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: null
16:16:09,613 ERROR JDBCExceptionReporter:78 - The value is not set for the parameter number 3.
hibernate 3.2.6
Mapping
<hibernate-mapping >
<class name="dwbridge.dailygross" table="dwf_daily_site_gross_sales_by_revclass" >
<!-- Primary Key
-->
<id name="id" column="rev_class_gross_id">
</id>
<property name="name" column="rev_class_name"/>
<property name="amount" >
<column name="rev_class_gross_amount" not-null="true" sql-type="NUMERIC(12,2)" />
</property>
</class>
<sql-query name="testgross" callable="true">
<return alias="dg" class="dwbridge.dailygross">
</return>
{ ? = call dwf_daily_site_gross_sales_by_revclass(?, ?) }
</sql-query>
</hibernate-mapping>
FUNCTION CALL TO EXECUTE FUNCTION
public void selectGross()
{
List list ;
dailygross dg = new dailygross();
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query =session.getNamedQuery("testgross")
.setParameter(0, "02/18/2008 00:00:00 AM")
.setParameter(1, "02/18/2008 08:00:00 PM") ;
System.out.println("query=" + query.getQueryString());
list = query.list();
System.out.println("listcount=" + list.size());
if ( list.size() > 0)
{
dg = (dailygross)list.get(0);
}
session.close();
}
I have been able to get the following PROCEDURE TO work
<class name="dwbridge.itemCategories" table="sp_getCategoriesForItem(" >
<id name="i_screen_category_id" >
</id>
<property name="s_button_name"/>
<property name="i_ordinal"/>
<property name="s_graphic"/>
<property name="b_active"/>
<!--
<property name="i_screencategory_genre_id"/>
-->
</class>
<sql-query name="test" callable="true">
<return alias="ic" class="dwbridge.itemCategories">
</return>
{ call sp_getCategoriesForItem( ?) }
</sql-query>
sp_getCategoriesForItem ...
SELECT dbo.ScreenCategory.*
FROM dbo.ScreenCategory
WHERE (b_active = 1) AND (i_screen_category_id IN
(SELECT i_screen_category_id
FROM ItemCategory
WHERE i_menu_item_id = @id))
ORDER BY i_ordinal
I am out of suggestions and there is not many examples out there. It appears that I am using proper syntax but function are note working. It always errors on the parameter 3.
|