Autocommit error with ActiveRecord JDBC, SQL Server & jTDS

Hi,

We have a problem with JRuby 1.1.1, MS SQL Server 2000, ARJDBC 0.8 and
jTDS
1.2.2.

When doing an update/insert we get an exception saying that
rollback/commit
should not be called while in auto-commit mode.

Our database.yml:

development:
username: my_user
password: ****
adapter: jdbc
url: jdbc:jtds:sqlserver://localhost:1433/my_database_development
driver: net.sourceforge.jtds.jdbc.Driver

Any ideas?

/Thor M.

Exception in thread “Ruby Thread22189158” java.sql.SQLException:
rollback()
should not be called while in auto-commit mode.
at
net.sourceforge.jtds.jdbc.ConnectionJDBC2.rollback(ConnectionJDBC2.java:2031)
at
jdbc_adapter.JdbcAdapterInternalService.rollback(JdbcAdapterInternalService.java:397)
at
jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown
Source)
at
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZero.call(JavaMethod.java:82)
at
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:66)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:101)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:238)
at
org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:682)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:309)
at
org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:169)
at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:172)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:148)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:223)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:116)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:270)
at
org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1792)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:485)
at
org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:632)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
at
org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:632)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
at
org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:632)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
at
org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1605)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:453)
at
org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:632)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
at
org.jruby.evaluator.ASTInterpreter.ensureNode(ASTInterpreter.java:1100)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:349)
at
org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:169)
at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:172)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:148)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:248)

I’ve been thinking of this myself, but jTDS doesn’t seem to accept the
autocommit parameter.

I’ve also noticed that java class JdbcAdapterInternalService for some
reason
is setting autocommit=true whenever it get’s a rollback or commit.

/Thor M.

Can jTDS receive the autocommit parameter through jdbc url?
Something
like:
jdbc:jtds:sqlserver://localhost:1433/my_database_development?autocommit=false,
or
jdbc:jtds:sqlserver://localhost:1433/my_database_development;autocommit=false

On Thu, May 15, 2008 at 10:15 AM, Thor Henrichsen
[email protected]
wrote:

development:
Exception in thread “Ruby Thread22189158” java.sql.SQLException: rollback()
at
at
org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1792)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:248)


Fabio K.
http://www.fabiokung.com

Caelum - Ensino e Soluções em Computação
http://www.caelum.com.br

On Thu, May 15, 2008 at 9:43 AM, Thor Henrichsen
[email protected] wrote:

Can jTDS receive the autocommit parameter through jdbc url?

This looks similar to http://jira.codehaus.org/browse/JRUBY-2422
although that issue pertains to MySQL. We may just not be handling
auto commit properly in the code; I’ll have to go back and look. If
you could comment on that issue, that would be great.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

It seems like the jTDS driver (v 1.2.2) has autocommit on by default. A
solution (at least for us) is to set autocommit = false in when the
connection is created in
active_record/connection/adapter/jdbc_adapter.rb#configure_jdbc. I
haven’t
tried this with other configurations than jTDS-1.2.2 & MS SQL Server
2000:

@connection_factory = JdbcConnectionFactory.impl do
conn = jdbc_driver.connection(url, user, pass)

Turn off autocommit just to be sure. (Some drivers, i.e. jtds have

it on
by default)
conn.setAutoCommit(false)
conn
end

Patch coming soon

/Thor M.

On Fri, May 16, 2008 at 8:16 AM, Christian S. [email protected]
wrote:

I used to have the same problem, but it seems like I just found out what
caused the trouble at least with my setup: I had my own version of the MySQL
JDBC driver (5.0.8) in the classpath ($CLASSPATH <<). When I remove the jar
file, the error doesn’t happen anymore. Obviously AR-JDBC uses a bundled
version of the driver?

It does, but that shouldn’t prevent you from using your own version.
If you use the ‘jdbcmysql’ adapter, the adapter gets included for you
currently, but we could check if the driver is already available by
trying to load the class.

Do you have a need to use your own driver? The bundled one is
certainly a few revs behind but it works, and I seem to recall a few
quirks and differences between minor revisions of the same JDBC
driver.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I used to have the same problem, but it seems like I just found out what
caused the trouble at least with my setup: I had my own version of the
MySQL
JDBC driver (5.0.8) in the classpath ($CLASSPATH <<). When I remove the
jar
file, the error doesn’t happen anymore. Obviously AR-JDBC uses a bundled
version of the driver?

My setup:
Ubuntu 8.04, JDK6, JRuby1.1.1, AR-JDBC 0.8, MySQL 5.0.51a

The exception (which has gone away now):

Exception in thread “main”
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Can’t
call
rollback when autocommit=true
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
at com.mysql.jdbc.Connection.rollback(Connection.java:5257)
at
jdbc_adapter.JdbcAdapterInternalService.rollback(JdbcAdapterInternalService.java:397)
at
jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown
Source)
at
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZero.call(JavaMethod.java:82)

Chris

Thor Henrichsen wrote:

jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown
org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:682)
at
org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:303)
at
org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:169)
at
org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:172)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:148)
at
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:248)


View this message in context:
http://www.nabble.com/autocommit-error-with-ActiveRecord-JDBC%2C-SQL-Server---jTDS-tp17253036p17274447.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, May 16, 2008 at 11:41 AM, Christian S. [email protected]
wrote:

I changed this to “adapter: jdbcmysql”. I had to download the
activerecord-jdbcmysql-adapter gem and now it works in both cases (JDBC
driver on classpath or not).

I assume that the activerecord-jdbcmysql-adapter gem includes the JDBC
driver?

Yes.

If that’s true which one was used before I had installed the gem?
Hmm…

Whatever was on your classpath. If you don’t use ‘jdbcmysql’ then you
need to ensure it’s there yourself.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Nick S.-2 wrote:

version of the driver?

It does, but that shouldn’t prevent you from using your own version.
If you use the ‘jdbcmysql’ adapter, the adapter gets included for you
currently, but we could check if the driver is already available by
trying to load the class.

Oh, it seems like I was using a very outdated ar-jdbc configuration:

adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1/…

I changed this to “adapter: jdbcmysql”. I had to download the
activerecord-jdbcmysql-adapter gem and now it works in both cases (JDBC
driver on classpath or not).

I assume that the activerecord-jdbcmysql-adapter gem includes the JDBC
driver? If that’s true which one was used before I had installed the
gem?
Hmm…

Nick S.-2 wrote:

Do you have a need to use your own driver? The bundled one is
certainly a few revs behind but it works, and I seem to recall a few
quirks and differences between minor revisions of the same JDBC
driver.

Not really. I have a little Java backend in my Rails app, which has the
ability to run a few command-line tasks without Rails/Ruby. So it needs
the
JDBC driver, too. I simply add all jar files to the $CLASSPATH in
environment.rb, but I can exclude the JDBC driver, of course. I probably
will do this to avoid any problems like this.


View this message in context:
http://www.nabble.com/autocommit-error-with-ActiveRecord-JDBC%2C-SQL-Server---jTDS-tp17253036p17279105.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs