These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: "startIndex should be greater than or equal to 0"
PostPosted: Tue Oct 31, 2006 5:39 pm 
Newbie

Joined: Tue Jun 07, 2005 4:39 pm
Posts: 10
In the past I've used Nhibernate 1.0.1.0 in an ASP.NET 1.1 application with SQL Server 2000 with a lot of success. Now I'm creating a .NET 2.0 Windows Application with NHibernate 1.2.0-beta1 and MS Access 2003. I'm just starting to set it up and only have one class mapped (ProjectUnitCostSchedule). It's a simple class with only two fields.

To test things out I created a test object of ProjectUnitCostSchedule but when I try storing it in the database I get the exception listed below. The weird thing is that the line in JetDriver.cs that is just before the exception is thrown is:

string fromClause = sqlString.Substring(beginOfFrom, endOfFrom - beginOfFrom).ToString();

It's getting a startIndex less than 0 (I assume) because the index of "from" and "where" are both -1, which is correct since I'm just doing an INSERT. But I don't get why JetDriver is looking for a SELECT statement. I've also never seen this exception before. I've played around with the mapping files a bit but it looks like they're correct.

Any ideas?


Hibernate version:
1.2.0-beta1

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="STS" assembly="STS">
<class name="ProjectUnitCostSchedule" table="PROJECTUNITCOSTSCHEDULE">
<id name="Id" unsaved-value="0">
<column name="id" sql-type="Int32" not-null="true" />
<generator class="identity" />
</id>
<property name="ScheduleType">
<column name="scheduleType" />
</property>
<property name="ScheduleTitle">
<column name="scheduleTitle" />
</property>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
ISession session = NHibernateFactoryProvider.GetInstance().GetFactoryInstance().OpenSession();
ITransaction transaction = session.BeginTransaction();

session.SaveOrUpdate(o);

transaction.Commit();

session.Flush();
session.Close();

Full stack trace of any exception that occurs:
WARN 2006-10-31 13:17:50,012 1421ms ADOExceptionReporter LogExceptions - System.ArgumentException: startIndex should be greater than or equal to 0
Parameter name: startIndex
at NHibernate.SqlCommand.SqlString.Substring(Int32 startIndex, Int32 length) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\SqlCommand\SqlString.cs:line 299
at NHibernate.JetDriver.JetDriver.FinalizeJoins(SqlString sqlString) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate.JetDriver\JetDriver.cs:line 112
at NHibernate.JetDriver.JetDriver.GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate.JetDriver\JetDriver.cs:line 34
at NHibernate.Impl.BatcherImpl.Generate(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\BatcherImpl.cs:line 64
at NHibernate.Impl.BatcherImpl.PrepareCommand(CommandType type, SqlString sql, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\BatcherImpl.cs:line 145
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 1997
ERROR 2006-10-31 13:17:50,043 1453ms ADOExceptionReporter LogExceptions - startIndex should be greater than or equal to 0
Parameter name: startIndex
ERROR 2006-10-31 13:17:50,043 1453ms Logger Error - Error creating and storing test ProjectUnitCostSchedule
NHibernate.ADOException: could not insert: [STS.ProjectUnitCostSchedule][SQL: INSERT INTO PROJECTUNITCOSTSCHEDULE (scheduleType, scheduleTitle) VALUES (?, ?)] ---> System.ArgumentException: startIndex should be greater than or equal to 0
Parameter name: startIndex
at NHibernate.SqlCommand.SqlString.Substring(Int32 startIndex, Int32 length) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\SqlCommand\SqlString.cs:line 299
at NHibernate.JetDriver.JetDriver.FinalizeJoins(SqlString sqlString) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate.JetDriver\JetDriver.cs:line 112
at NHibernate.JetDriver.JetDriver.GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate.JetDriver\JetDriver.cs:line 34
at NHibernate.Impl.BatcherImpl.Generate(CommandType type, SqlString sqlString, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\BatcherImpl.cs:line 64
at NHibernate.Impl.BatcherImpl.PrepareCommand(CommandType type, SqlString sql, SqlType[] parameterTypes) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\BatcherImpl.cs:line 145
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 1997
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2017
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2387
at NHibernate.Impl.ScheduledIdentityInsertion.Execute() in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\ScheduledIdentityInsertion.cs:line 38
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 3283
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1002
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 914
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 809
at NHibernate.Impl.SessionImpl.Save(Object obj) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 750
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) in c:\net\nhibernate-1.2.0.Beta1\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1581
at STS.ModelManager.Store(Object o) in C:\Documents and Settings\Dale.DEVINECO\My Documents\Visual Studio 2005\Projects\STS\STS\ModelManager.cs:line 31
at STS.MainForm..ctor() in C:\Documents and Settings\Dale.DEVINECO\My Documents\Visual Studio 2005\Projects\STS\STS\MainForm.cs:line 46

Name and version of the database you are using:
MS Access 2003


Top
 Profile  
 
 Post subject: Ok, I figured it out.
PostPosted: Tue Oct 31, 2006 6:00 pm 
Newbie

Joined: Tue Jun 07, 2005 4:39 pm
Posts: 10
It turns out I'm just retarded. After stepping through the lines of code in the stack trace, it looks like NHibernate was unable to create an identity for the object, which was calling methods to reformat the SQL.

It looks like I can't use:

<generator class="identity" />

with Access. So, I changed it to:

<generator class="increment" />

and it works just fine now.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 3:15 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please report it to JIRA, the exception shouldn't occur nevertheless.


Top
 Profile  
 
 Post subject: Re: Ok, I figured it out.
PostPosted: Thu Nov 02, 2006 4:23 am 
Newbie

Joined: Thu Oct 05, 2006 12:38 am
Posts: 8
Hmm, I'm getting the same error but I'm using <generator class="native" /> Isn't native suppose to means that the dialect will actually choose the appropriate sql insert procedure for JetDriver in this case.

Apparently the method SupportsIdentitySelectInInsert in JetDialect no longer exists. Its replace by:

public override SqlString AddIdentitySelectToInsert( SqlString insertSql,
string identityColumn, string tableName )
{
return null;
}

which I think is suppose to serve the same purpose.

Any idea how to make "native" work, I want to be able to switch between Access and SQL seamlessly without changing the mapping files everytime.

dgundersen wrote:
It turns out I'm just retarded. After stepping through the lines of code in the stack trace, it looks like NHibernate was unable to create an identity for the object, which was calling methods to reformat the SQL.

It looks like I can't use:

<generator class="identity" />

with Access. So, I changed it to:

<generator class="increment" />

and it works just fine now.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:45 pm 
Newbie

Joined: Thu Dec 21, 2006 1:41 pm
Posts: 4
Same error here... I'm using native method and it throws the same error when selecting and inserting..
Also changed the <generator> to "increment" and that doesn't solve the problem...
If found a solution please post it..

Thanks, Diego


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.