Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate OleDB: Invalid program bind when using session.get<T>(id)
    primarykey
    data
    text
    <p>I'm using NHibernate for the first time. I've set it up to use OleDB to connect to a SQLBase database. I've set up a few of my classes and now tried the first short test to see if it works. </p> <p>This is my test:</p> <pre><code>[TestClass] public class Hibernate { private ISessionFactory _sessionFactory; private Configuration _config; [TestInitialize] public void InitTest() { _config = new Configuration(); _config.Configure(); _config.AddAssembly(typeof(Coil).Assembly); _sessionFactory = _config.BuildSessionFactory(); } [TestMethod] public void TestMethod1() { using (var session = _sessionFactory.OpenSession()) { Int32 coilid = 12189; Coil coil = session.Get&lt;Coil&gt;(coilid); Assert.AreEqual(coil.CoilNumber, "6FEB13"); } } } </code></pre> <p>And here's the relevant part of the mapping:</p> <pre><code>&lt;class name="Coil" table="COIL"&gt; &lt;id name="ID" column="COILID" type="integer"&gt; &lt;generator class="hilo"&gt; &lt;param name="table"&gt;DEFTAB&lt;/param&gt; &lt;param name="column"&gt;WERT1&lt;/param&gt; &lt;param name="max_lo"&gt;10&lt;/param&gt; &lt;param name="where"&gt;TBCODE='LFDNR' AND CODE='WGID'&lt;/param&gt; &lt;/generator&gt; &lt;/id&gt; &lt;property name="CoilNumber" column="COILNR" type="string" /&gt; &lt;/class&gt; </code></pre> <p>When I try to run my simple test, I get an GenericADOException: could not load an entity. [SQL: SELECT ... WHERE coil0_.COILID=?] ---> System.Data.OleDb.OleDbException: Invalid program bind variable.</p> <p>When I copy the SELECT ... WHERE coil0_.COILID=12189 to a SQLbase client the query succeeds without any error. The problem is that somehow NHibernate doesn't put my id variable into the query and instead simply puts a ? there.</p> <p>Am I just using a wrong syntax in my test or do I have some configuration problem?</p> <p>At last my hibernate config file if it helps:</p> <pre><code> &lt;session-factory&gt; &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt; &lt;property name="dialect"&gt;NHibernate.Dialect.GenericDialect&lt;/property&gt; &lt;property name="connection.driver_class"&gt;NHibernate.Driver.OleDbDriver&lt;/property&gt; &lt;property name="connection.connection_string"&gt;Provider=SQLBASEOLEDB.1;Password=XXX;User ID=XXX;Data Source=XXX&lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; </code></pre> <p></p> <p>Again, the SQL output is fine but I don't get why NHibernate doesn't put the ID I use for the function into the SQL query.</p> <p>Edit: COILID is a normal INTEGER in the database table, and a int in the Coil class.</p> <p>Edit2: Here's the stack trace</p> <pre><code>System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object&amp; executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&amp; executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object&amp; executeResult) System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader() NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session) NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session) NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) NHibernate.Impl.SessionImpl.Get(String entityName, Object id) NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id) NHibernate.Impl.SessionImpl.Get[T](Object id) Tests.Hibernate.TestMethod1() in "D:\Hibernate.cs": Zeile 36 </code></pre> <p>The create table syntax for the Coil table is as follows:</p> <pre><code>CREATE TABLE COIL ( COILID INTEGER NOT NULL, COILNR VARCHAR(50), ); </code></pre> <p>Edit5: Querying all entries works, but as soon as I want to get a specific entry from the table I get the ? error again :(</p> <pre><code>var allCoils = session.CreateCriteria&lt;Coil&gt;().List&lt;Coil&gt;(); Coil datCoil = allCoils.First&lt;Coil&gt;(coil =&gt; coil.CoilNumber == "6FEB13"); Assert.AreEqual(datCoil.CoilNumber, "6FEB13"); </code></pre> <p>This test is successful at least</p> <p>Edit6: The problem seems to be that nhibernate prepares the sql like this:</p> <pre><code>DEBUG NHibernate.SQL - SELECT coil0_.COILID as COILID1_0_, coil0_.COILNR as COILNR1_0_ FROM COIL coil0_ WHERE coil0_.COILID=?;p0 = 12189 </code></pre> <p>but SQLbase wants prepared strings like</p> <pre><code>WHERE coil0_.COILID = :0 \ 12189 / </code></pre> <p>What would I have to do to change the way nhibernate transforms the bind variables into SQL?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload