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.  [ 3 posts ] 
Author Message
 Post subject: (Version && select-before-update) cause ORA-01036
PostPosted: Thu Aug 23, 2007 10:55 am 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Here is the set-up:
* I'm using oracle 10g
* my class mapping has a version
* my class mapping has select-before-update

I get an ORA-01036. I traced the code and found the problem. Can someone out there tell me if this is a NHibernate bug, or maybe i'm using the wrong driver or something?

I can't imagine that we are the ONLY dev shop on the planet with the above setup. Please advise.

Here is what I found when I traced the code:
---------------------------------------------------
1. This method generates the SQL string for the snapshot select used in select-for-update cases. I am highlighting a piece of code that is half-heartedly adding a version column, but not truly as a bind variable parameter. There is also a TODO comment here:

protected virtual SqlString GenerateSnapshotSelectString()
{
....
// TODO H3: this is commented out in H3.2
if (IsVersioned)
{
whereClause.Append(" and ")
.Append(VersionColumnName)
.Append("=?");
}
...
}

2.
This method creates command object and adds parameters. It is adding both ID and version Parameters to the command object expecting the SQL string generated contains both bind variables, however, the version column was not truly added a bind variable parameter earlier.

public object[] GetDatabaseSnapshot() {
...
IDbCommand st = session.Batcher.PrepareCommand(CommandType.Text, sql, idAndVersionSqlTypes);
...
}


This doesn't seem to pose a problem to SQL Server driver, but the Oracle driver is complaining with ORA-01036 because of the extra parameter added to the command but a non-existent bind variable.

To test the theory, I changed the fragment in the first method to this and it works in both drivers, because it is adding the parameter rather than just a string:

if (IsVersioned)
{
whereClause = whereClause.Append(" and ")
.Append(VersionColumnName)
.Append("=")
.Append(new SqlStringBuilder().AddParameter().ToSqlString());
}

Please advise.

Thanks


Top
 Profile  
 
 Post subject: That's the theory. Debugging shows different
PostPosted: Tue May 13, 2008 2:15 pm 
Newbie

Joined: Mon Feb 25, 2008 7:02 am
Posts: 3
Location: London
Hi there,

I've encountered the same problem and downloaded NHibernate source code to debug. What I have found is that the real problem is in SqlString class - Append method does not append anything unfortunately. So when on previous statement ID property is appended - it works because Append is called on SqlStringBuilder, but when Version is added - it uses SqlString.Append... which doesn't work.

This method (GenerateSnapshotSelectString) is implemented better for joined subclassed, although there is another bug - when joining superclass table to subclass table aliases are not being added hence if primary key column name on superclass table is the same as foreign key column on subclass (which is quite common) invalid SQL query will get generated and "ORA-00918: column ambiguously defined" will be the result.

Will appreciate if you have it fixed.
Regards,
Max.


Top
 Profile  
 
 Post subject: Re: That's the theory. Debugging shows different
PostPosted: Mon Sep 15, 2008 10:18 am 
Newbie

Joined: Sun Sep 14, 2008 6:40 pm
Posts: 6
starwalk wrote:
Hi there,

I've encountered the same problem and downloaded NHibernate source code to debug. What I have found is that the real problem is in SqlString class - Append method does not append anything unfortunately. So when on previous statement ID property is appended - it works because Append is called on SqlStringBuilder, but when Version is added - it uses SqlString.Append... which doesn't work.



Same problem here:
Oracle 10g, select-before-update, version. Since I'm using ActiveRecord from Castle project, I cannot switch to NH 2.0.

I downloaded the NH 1.2 sources made two small changes and it seems to work. I don't have enough time to submit a fix, but you can do it by yourself.
Simply download the 1.2 from https://nhibernate.svn.sourceforge.net/ ... s/1.2.0.GA, and edit the file:
/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs:
line ~1538, remove the if (isVersioned) with its body,
line ~2353, remove the if (isVersioned) with its body.
Recompile. Done.


WARNING:
It's a quickfixk and I am NOT sure if it doesn't break some other functionality.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.