I have been attempting to get just a small example working calling a stored procedure in MS SQL without success. I have read the 3.1 documentation several times and checkedout the FAQ but still do not understand what I am doing incorrectly.
I get the following exception when the call is executed:
[java] java.sql.SQLException: Parameter #1 has not been set.
I hope the following is enough for someone to point me in the correct direction as to what I am doing incorrectly. Thanks
Hibernate version: 3.1
Mapping documents: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class entity-name="Event"> <id name="id" column="EVENT_ID" type="long"> <generator class="native"/> </id> <property name="date" type="timestamp" column="EVENT_DATE"/> <property name="title" type="string" column="title"/> </class> <sql-query name="EventXXX_SP" callable="true"> <return class="Event"></return> { ? = call eventXXX() } </sql-query> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): private List SP() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); List result = session.getNamedQuery("EventXXX_SP").list(); session.getTransaction().commit(); return result; }
Full stack trace of any exception that occurs: :\JavaDev\lib\dom4j-1.6.1.jar;C:\JavaDev\lib\hibernate3.jar;C:\JavaDev\lib\hsqld b.jar;C:\JavaDev\lib\jta.jar;C:\JavaDev\lib\jtds-1.2.jar;C:\JavaDev\lib\log4j-1. 2.11.jar;C:\JavaDev\lib\servlet.jar, hibernate.show_sql=true, current_session_co ntext_class=thread, java.vm.specification.version=1.0, java.home=C:\Java\jdk1.5. 0_04\jre, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.SQLSer verDialect, hibernate.connection.url=jdbc:jtds:sqlserver://usmv-harrisrm1, conne ction.pool_size=1, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optim izer=true, java.vm.info=mixed mode, java.version=1.5.0_04, java.ext.dirs=C:\Java \jdk1.5.0_04\jre\lib\ext, sun.boot.class.path=C:\Java\jdk1.5.0_04\jre\lib\rt.jar ;C:\Java\jdk1.5.0_04\jre\lib\i18n.jar;C:\Java\jdk1.5.0_04\jre\lib\sunrsasign.jar ;C:\Java\jdk1.5.0_04\jre\lib\jsse.jar;C:\Java\jdk1.5.0_04\jre\lib\jce.jar;C:\Jav a\jdk1.5.0_04\jre\lib\charsets.jar;C:\Java\jdk1.5.0_04\jre\classes, java.vendor= Sun Microsystems Inc., connection.driver_class=net.sourceforge.jtds.jdbc.Driver, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi , sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=wind ows, connection.url=jdbc:jtds:sqlserver://usmv-harrisrm1, dialect=org.hibernate. dialect.SQLServerDialect, sun.cpu.isalist=} [java] 15:14:29,982 DEBUG Configuration:1145 - Preparing to build session f actory with filters : {} [java] 15:14:29,982 INFO Configuration:1022 - processing extends queue [java] 15:14:29,982 INFO Configuration:1026 - processing collection mappin gs [java] 15:14:29,982 INFO Configuration:1035 - processing association prope rty references [java] 15:14:29,982 INFO Configuration:1057 - processing foreign key const raints [java] 15:14:30,060 INFO DriverManagerConnectionProvider:41 - Using Hibern ate built-in connection pool (not for production use!) [java] 15:14:30,060 INFO DriverManagerConnectionProvider:42 - Hibernate co nnection pool size: 1 [java] 15:14:30,060 INFO DriverManagerConnectionProvider:45 - autocommit m ode: false [java] 15:14:30,060 INFO DriverManagerConnectionProvider:80 - using driver : net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://usmv-harrisrm1 [java] 15:14:30,060 INFO DriverManagerConnectionProvider:83 - connection p roperties: {user=sa, password=robert} [java] 15:14:30,060 DEBUG DriverManagerConnectionProvider:93 - total checke d-out connections: 0 [java] 15:14:30,060 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection [java] 15:14:30,216 DEBUG DriverManagerConnectionProvider:115 - created con nection to: jdbc:jtds:sqlserver://usmv-harrisrm1, Isolation Level: 2 [java] 15:14:30,216 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server, version: 08.00.0818 [java] 15:14:30,216 INFO SettingsFactory:78 - JDBC driver: jTDS Type 4 JDB C Driver for MS SQL Server and Sybase, version: 1.2 [java] 15:14:30,216 DEBUG DriverManagerConnectionProvider:129 - returning c onnection to pool, pool size: 1 [java] 15:14:30,247 INFO Dialect:103 - Using dialect: org.hibernate.dialec t.SQLServerDialect [java] 15:14:30,247 INFO TransactionFactoryFactory:31 - Using default tran saction strategy (direct JDBC transactions) [java] 15:14:30,247 INFO TransactionManagerLookupFactory:33 - No Transacti onManagerLookup configured (in JTA environment, use of read-write or transaction al second-level cache is not recommended) [java] 15:14:30,247 INFO SettingsFactory:125 - Automatic flush during befo reCompletion(): disabled [java] 15:14:30,247 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled [java] 15:14:30,247 INFO SettingsFactory:144 - Scrollable result sets: ena bled [java] 15:14:30,247 DEBUG SettingsFactory:148 - Wrap result sets: disabled [java] 15:14:30,263 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): e nabled [java] 15:14:30,263 INFO SettingsFactory:160 - Connection release mode: au to [java] 15:14:30,263 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 15:14:30,263 INFO SettingsFactory:191 - Generate SQL with comments: disabled [java] 15:14:30,263 INFO SettingsFactory:195 - Order SQL updates by primar y key: disabled [java] 15:14:30,263 INFO SettingsFactory:338 - Query translator: org.hiber nate.hql.ast.ASTQueryTranslatorFactory [java] 15:14:30,263 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran slatorFactory [java] 15:14:30,263 INFO SettingsFactory:203 - Query language substitution s: {} [java] 15:14:30,263 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 15:14:30,263 INFO SettingsFactory:213 - Query cache: disabled [java] 15:14:30,263 INFO SettingsFactory:325 - Cache provider: org.hiberna te.cache.NoCacheProvider [java] 15:14:30,263 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled [java] 15:14:30,263 INFO SettingsFactory:237 - Structured second-level cac he entries: disabled [java] 15:14:30,279 DEBUG SQLExceptionConverterFactory:52 - Using dialect d efined converter [java] 15:14:30,279 INFO SettingsFactory:257 - Echoing all SQL to stdout [java] 15:14:30,279 INFO SettingsFactory:264 - Statistics: disabled [java] 15:14:30,279 INFO SettingsFactory:268 - Deleted entity synthetic id entifier rollback: disabled [java] 15:14:30,279 INFO SettingsFactory:283 - Default entity-mode: pojo [java] 15:14:30,310 INFO SessionFactoryImpl:153 - building session factory
[java] 15:14:30,310 DEBUG SessionFactoryImpl:164 - Session factory construc ted with filter configurations : {} [java] 15:14:30,310 DEBUG SessionFactoryImpl:167 - instantiating session fa ctory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standa rd Edition, hibernate.connection.password=robert, hibernate.cache.provider_class =org.hibernate.cache.NoCacheProvider, sun.boot.library.path=C:\Java\jdk1.5.0_04\ jre\bin, java.vm.version=1.5.0_04-b05, hibernate.connection.username=sa, java.vm .vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separa tor=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.c ountry=US, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Vi rtual Machine Specification, user.dir=C:\JavaDev, java.runtime.version=1.5.0_04- b05, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, hibernate.current_se ssion_context_class=thread, java.endorsed.dirs=C:\Java\jdk1.5.0_04\jre\lib\endor sed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\harrisbm\LOCALS~1\Temp\, line.separ ator= [java] , java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, cache.provider_class=org.hibernate.cache.NoCacheProvider, os.name=Windows XP, s un.jnu.encoding=Cp1252, java.library.path=C:\Java\jdk1.5.0_04\jre\bin;.;C:\WINDO WS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C :\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin;C:\WINDOWS\Microsoft.NET\ Framework\v2.0.50215;C:\apache-ant-1.6.5\bin;C:\Program Files\Microsoft SQL Serv er\80\Tools\BINN;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\RulesMo deler\RM00\Bin\Debug;C:\Sun\jwsdp-1.6\jwsdp-shared\bin;C:\Sun\AppServer\bin;C:\e clipse\bpelz_install\bin, java.specification.name=Java Platform API Specificatio n, java.class.version=49.0, hibernate.connection.pool_size=1, sun.management.com piler=HotSpot Client Compiler, os.version=5.1, user.home=C:\Documents and Settin gs\harrisbm, connection.password=robert, user.timezone=America/Los_Angeles, java .awt.printerjob=sun.awt.windows.WPrinterJob, connection.username=sa, java.specif ication.version=1.5, file.encoding=Cp1252, hibernate.connection.driver_class=net .sourceforge.jtds.jdbc.Driver, show_sql=true, java.class.path=C:\JavaDev\bin;C:\ JavaDev\lib\ant-antlr-1.6.5.jar;C:\JavaDev\lib\antlr-2.7.5H3.jar;C:\JavaDev\lib\ antlr-2.7.6rc1.jar;C:\JavaDev\lib\asm-attrs.jar;C:\JavaDev\lib\asm.jar;C:\JavaDe v\lib\cglib-2.1.2.jar;C:\JavaDev\lib\cglib-2.1.3.jar;C:\JavaDev\lib\commons-coll ections-2.1.1.jar;C:\JavaDev\lib\commons-logging-1.0.4.jar;C:\JavaDev\lib\dom4j- 1.6.1.jar;C:\JavaDev\lib\hibernate3.jar;C:\JavaDev\lib\hsqldb.jar;C:\JavaDev\lib \jta.jar;C:\JavaDev\lib\jtds-1.2.jar;C:\JavaDev\lib\log4j-1.2.11.jar;C:\JavaDev\ lib\servlet.jar, user.name=HarrisBM, hibernate.show_sql=true, current_session_co ntext_class=thread, java.vm.specification.version=1.0, sun.arch.data.model=32, j ava.home=C:\Java\jdk1.5.0_04\jre, hibernate.connection.url=jdbc:jtds:sqlserver:/ /usmv-harrisrm1, hibernate.dialect=org.hibernate.dialect.SQLServerDialect, java. specification.vendor=Sun Microsystems Inc., user.language=en, connection.pool_si ze=1, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, hibernate.c glib.use_reflection_optimizer=true, java.version=1.5.0_04, java.ext.dirs=C:\Java \jdk1.5.0_04\jre\lib\ext, sun.boot.class.path=C:\Java\jdk1.5.0_04\jre\lib\rt.jar ;C:\Java\jdk1.5.0_04\jre\lib\i18n.jar;C:\Java\jdk1.5.0_04\jre\lib\sunrsasign.jar ;C:\Java\jdk1.5.0_04\jre\lib\jsse.jar;C:\Java\jdk1.5.0_04\jre\lib\jce.jar;C:\Jav a\jdk1.5.0_04\jre\lib\charsets.jar;C:\Java\jdk1.5.0_04\jre\classes, java.vendor= Sun Microsystems Inc., file.separator=\, connection.driver_class=net.sourceforge .jtds.jdbc.Driver, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi , sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=wind ows, connection.url=jdbc:jtds:sqlserver://usmv-harrisrm1, sun.cpu.isalist=, dial ect=org.hibernate.dialect.SQLServerDialect} [java] 15:14:30,450 DEBUG AbstractEntityPersister:2447 - Static SQL for ent ity: Event [java] 15:14:30,450 DEBUG AbstractEntityPersister:2449 - Version select: s elect EVENT_ID from Event where EVENT_ID =? [java] 15:14:30,450 DEBUG AbstractEntityPersister:2450 - Snapshot select: select event_.EVENT_ID, event_.EVENT_DATE as EVENT2_0_, event_.title as title0_ from Event event_ where event_.EVENT_ID=? [java] 15:14:30,450 DEBUG AbstractEntityPersister:2452 - Insert 0: insert into Event (EVENT_DATE, title, EVENT_ID) values (?, ?, ?) [java] 15:14:30,450 DEBUG AbstractEntityPersister:2453 - Update 0: update Event set EVENT_DATE=?, title=? where EVENT_ID=? [java] 15:14:30,450 DEBUG AbstractEntityPersister:2454 - Delete 0: delete from Event where EVENT_ID=? [java] 15:14:30,450 DEBUG AbstractEntityPersister:2457 - Identity insert: insert into Event (EVENT_DATE, title) values (?, ?) [java] 15:14:30,482 DEBUG EntityLoader:79 - Static select for entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DATE as EVENT2_0_0_, even t0_.title as title0_0_ from Event event0_ where event0_.EVENT_ID=? [java] 15:14:30,482 DEBUG EntityLoader:79 - Static select for entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DATE as EVENT2_0_0_, even t0_.title as title0_0_ from Event event0_ where event0_.EVENT_ID=? [java] 15:14:30,482 DEBUG EntityLoader:79 - Static select for entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DATE as EVENT2_0_0_, even t0_.title as title0_0_ from Event event0_ where event0_.EVENT_ID=? [java] 15:14:30,482 DEBUG EntityLoader:79 - Static select for entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DATE as EVENT2_0_0_, even t0_.title as title0_0_ from Event event0_ where event0_.EVENT_ID=? [java] 15:14:30,497 DEBUG EntityLoader:67 - Static select for action ACTION _MERGE on entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_DA TE as EVENT2_0_0_, event0_.title as title0_0_ from Event event0_ where event0_.E VENT_ID=? [java] 15:14:30,497 DEBUG EntityLoader:67 - Static select for action ACTION _REFRESH on entity Event: select event0_.EVENT_ID as EVENT1_0_0_, event0_.EVENT_ DATE as EVENT2_0_0_, event0_.title as title0_0_ from Event event0_ where event0_ .EVENT_ID=? [java] 15:14:30,497 DEBUG SessionFactoryObjectFactory:39 - initializing cla ss SessionFactoryObjectFactory [java] 15:14:30,497 DEBUG SessionFactoryObjectFactory:76 - registered: 40bb 5e3b0854c089010854c089e10000 (unnamed) [java] 15:14:30,497 INFO SessionFactoryObjectFactory:82 - Not binding fact ory to JNDI, no JNDI name configured [java] 15:14:30,497 DEBUG SessionFactoryImpl:292 - instantiated session fac tory [java] 15:14:30,497 INFO SessionFactoryImpl:353 - Checking 0 named HQL que ries [java] 15:14:30,497 INFO SessionFactoryImpl:373 - Checking 1 named SQL que ries [java] 15:14:30,513 DEBUG SessionFactoryImpl:381 - Checking named SQL query : EventXXX_SP [java] 15:14:30,513 DEBUG QueryPlanCache:111 - unable to locate native-sql query plan in cache; generating ({ ? = call eventXXX() }) [java] 15:14:30,544 DEBUG SessionImpl:272 - opened session at timestamp: 11 352932705 [java] 15:14:30,622 DEBUG ThreadLocalSessionContext:282 - allowing method [ beginTransaction] in non-transacted context [java] 15:14:30,622 DEBUG JDBCTransaction:54 - begin [java] 15:14:30,622 DEBUG ConnectionManager:313 - opening JDBC connection [java] 15:14:30,622 DEBUG DriverManagerConnectionProvider:93 - total checke d-out connections: 0 [java] 15:14:30,622 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0 [java] 15:14:30,622 DEBUG JDBCTransaction:59 - current autocommit status: f alse [java] 15:14:30,622 DEBUG JDBCContext:202 - after transaction begin [java] 15:14:30,638 DEBUG QueryPlanCache:117 - located native-sql query pla n in cache ({ ? = call eventXXX() }) [java] 15:14:30,638 DEBUG SessionImpl:1597 - SQL query: { ? = call eventXXX () } [java] 15:14:30,638 DEBUG AbstractBatcher:311 - about to open PreparedState ment (open PreparedStatements: 0, globally: 0) [java] 15:14:30,638 DEBUG SQL:346 - { ? = call eventXXX() } [java] Hibernate: { ? = call eventXXX() } [java] 15:14:30,638 DEBUG AbstractBatcher:424 - preparing statement [java] 15:14:30,638 DEBUG AbstractBatcher:319 - about to close PreparedStat ement (open PreparedStatements: 1, globally: 1) [java] 15:14:30,638 DEBUG AbstractBatcher:470 - closing statement [java] 15:14:30,654 DEBUG JDBCExceptionReporter:63 - could not execute quer y [{ ? = call eventXXX() }] [java] java.sql.SQLException: Parameter #1 has not been set. [java] at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:100 5) [java] at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatem ent.java:478) [java] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsP reparedStatement.java:478) [java] at org.hibernate.dialect.SybaseDialect.getResultSet(SybaseDialec t.java:149) [java] at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatch er.java:146) [java] at org.hibernate.loader.Loader.getResultSet(Loader.java:1666) [java] at org.hibernate.loader.Loader.doQuery(Loader.java:662) [java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec tions(Loader.java:224) [java] at org.hibernate.loader.Loader.doList(Loader.java:2150) [java] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java: 2029) [java] at org.hibernate.loader.Loader.list(Loader.java:2024) [java] at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.ja va:117) [java] at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.ja va:1607) [java] at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionIm pl.java:121) [java] at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169) [java] at events.EventManager.SP(Unknown Source) [java] at events.EventManager.main(Unknown Source) [java] 15:14:30,654 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState : 07000 [java] 15:14:30,654 ERROR JDBCExceptionReporter:72 - Parameter #1 has not b een set. [java] Exception in thread "main" org.hibernate.exception.SQLGrammarExcepti on: could not execute query [java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon verter.java:65) [java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep tionHelper.java:43) [java] at org.hibernate.loader.Loader.doList(Loader.java:2153) [java] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java: 2029) [java] at org.hibernate.loader.Loader.list(Loader.java:2024) [java] at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.ja va:117) [java] at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.ja va:1607) [java] at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionIm pl.java:121) [java] at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169) [java] at events.EventManager.SP(Unknown Source) [java] at events.EventManager.main(Unknown Source) [java] Caused by: java.sql.SQLException: Parameter #1 has not been set. [java] at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:100 5) [java] at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatem ent.java:478) [java] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsP reparedStatement.java:478) [java] at org.hibernate.dialect.SybaseDialect.getResultSet(SybaseDialec t.java:149) [java] at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatch er.java:146) [java] at org.hibernate.loader.Loader.getResultSet(Loader.java:1666) [java] at org.hibernate.loader.Loader.doQuery(Loader.java:662) [java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollec tions(Loader.java:224) [java] at org.hibernate.loader.Loader.doList(Loader.java:2150) [java] ... 8 more [java] Java Result: 1
BUILD SUCCESSFUL Total time: 3 seconds C:\JavaDev>
Name and version of the database you are using: MS SQL Sever 2000
Stored Procedure: CREATE PROCEDURE eventXXX AS SELECT * from EVENTS return 0 GO
|