Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roll back fail.... [JDBC224] #273

Closed
firebird-automations opened this issue Jan 4, 2012 · 13 comments
Closed

Roll back fail.... [JDBC224] #273

firebird-automations opened this issue Jan 4, 2012 · 13 comments

Comments

@firebird-automations
Copy link

Submitted by: Zhaoce (zhaoce)

Attachments:
Test.java

I am not sure this is a bug or not
but it seems like a bug to me
I built a table USERS with 2 columns ID and PW(password) with ID is the primary key
then I insert one record ("zhaoce", "fdjakl") and commit;

create table USERS\(ID varchar\(25\) primary key, PW varchar\(25\)\);
commit;
insert into USERS values\('zhaoce','fdjakl'\);
commit;
exit;

then I tried to use jdbc to insert this record again
it should fail and throw an exception and then I tried to rollback to the savepoint
but it failed and throw a new exception...

below is my jdbc test code

import java.sql.*;

public class Test {

/\*\*
 \* @param args
 \* @throws SQLException 
 \* @throws IOException
 \* @throws DocumentException
 \*/
public static void main\(String\[\] args\) \{
	// TODO Auto\-generated method stub
	Statement state=null;
	Connection conn=null;
	
	try \{
		Class\.forName\("org\.firebirdsql\.jdbc\.FBDriver"\)\.newInstance\(\);
		String url = "jdbc:firebirdsql:localhost/3050:/Users/zhaoce/Documents/Database/Core\.fdb";
		conn = DriverManager\.getConnection\(url, "SYSDBA", "masterkey"\);

		state = conn\.createStatement\(\);
		conn\.setAutoCommit\(false\);
		conn\.setSavepoint\(\);
		String sql = "insert into USERS values\('zhaoce','fdjakl'\)";//this record has already existed in the database
		state\.executeUpdate\(sql\);//throw an exception
		conn\.commit\(\);
	\} catch \(Exception e\) \{
		e\.printStackTrace\(\);
		try \{
			conn\.rollback\(\);//failed and throw another exception
		\} catch \(SQLException e1\) \{
			// TODO Auto\-generated catch block
			System\.out\.println\("roll back fail"\);
			e1\.printStackTrace\(\);
		\}
	\}finally\{
		if\(state\!=null\) try\{state\.close\(\);\}catch\(Exception e\)\{\}
		if\(conn\!=null\) try\{conn\.close\(\);\}catch\(Exception e\)\{\}
	\}
\}

}

@firebird-automations
Copy link
Author

Commented by: Zhaoce (zhaoce)

here is my test code
the connection url and username and password maybe different

@firebird-automations
Copy link
Author

Modified by: Zhaoce (zhaoce)

Attachment: Test.java [ 12082 ]

@firebird-automations
Copy link
Author

Commented by: Zhaoce (zhaoce)

here is the exception printout
I tried to run the hibernate transaction example
and spring transaction example
and I got the same error code exception which is 335544726. Error reading data from the connection.....

java.lang.ArrayIndexOutOfBoundsException: 1041
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.getSqlCounts(AbstractJavaGDSImpl.java:1619)
at org.firebirdsql.gds.impl.GDSHelper.getSqlCounts(GDSHelper.java:357)
at org.firebirdsql.jdbc.AbstractStatement.getUpdateCount(AbstractStatement.java:651)
at org.firebirdsql.jdbc.AbstractStatement.executeUpdate(AbstractStatement.java:271)
at test.Test.main(Test.java:27)
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544726. Error reading data from the connection.
Reason: Error reading data from the connection.
at org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.rollback(InternalTransactionCoordinator.java:335)
at org.firebirdsql.jdbc.InternalTransactionCoordinator.rollback(InternalTransactionCoordinator.java:87)
at org.firebirdsql.jdbc.AbstractConnection.rollback(AbstractConnection.java:461)
at test.Test.main(Test.java:32)
at org.firebirdsql.gds.GDSException: Error reading data from the connection.
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscRollbackTransaction(AbstractJavaGDSImpl.java:959)
at org.firebirdsql.gds.impl.GDSHelper.rollbackTransaction(GDSHelper.java:613)
at org.firebirdsql.jca.FBManagedConnection.internalRollback(FBManagedConnection.java:848)
at org.firebirdsql.jca.FBLocalTransaction.internalRollback(FBLocalTransaction.java:251)
at org.firebirdsql.jca.FBLocalTransaction.rollback(FBLocalTransaction.java:222)
at org.firebirdsql.jdbc.InternalTransactionCoordinator$LocalTransactionCoordinator.rollback(InternalTransactionCoordinator.java:333)
at org.firebirdsql.jdbc.InternalTransactionCoordinator.rollback(InternalTransactionCoordinator.java:87)
at org.firebirdsql.jdbc.AbstractConnection.rollback(AbstractConnection.java:461)
at test.Test.main(Test.java:32)
roll back fail

below is my hibernate test code

 public void save\(User user\) \{
	 
		Session session = HibernateUtil\.currentSession\(\);

		Transaction tx=null;

	try\{
		tx = session\.beginTransaction\(\);
		session\.save\(user\);
		tx\.commit\(\);
	\}catch\(Exception e\)\{
		e\.printStackTrace\(\);
		if\(tx\!=null\) try\{tx\.rollback\(\);\}catch\(Exception ee\)\{ee\.printStackTrace\(\);\};
		
	\}finally\{
		HibernateUtil\.closeSession\(\);
	\}

@firebird-automations
Copy link
Author

Modified by: Zhaoce (zhaoce)

security: Developers [ 10012 ] =>

@firebird-automations
Copy link
Author

Modified by: Zhaoce (zhaoce)

Version: Jaybird 2.1.6 [ 10285 ] =>

@firebird-automations
Copy link
Author

Modified by: Zhaoce (zhaoce)

environment: Mac OSX 10.5.8
Tomcat 6.0
JDK 1.6
Firebird 2.1

=>

Jaybird 2.1.6
Mac OSX 10.5.8
Tomcat 6.0
JDK 1.6
Firebird 2.1

@firebird-automations
Copy link
Author

Commented by: Zhaoce (zhaoce)

Today I tried another environment
I used Firebird 2.5 on linux which is ubuntu11
and run this program
it works fine and rollback did not fail....

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

What was the exact Firebird version and Java version you used previously (you mention Firebird 2.1 and JDK 1,6, but I need the full versions)?

@firebird-automations
Copy link
Author

Commented by: Zhaoce (zhaoce)

Hi Mark
Versions are:
FirebirdSS-2.1.4-18394-x86_64
and there are 3 jdk installd in my computer
programming environment version is 1.5.0_30
but tomcat is using 1.6.0_26
and I tried both JayBird 2.1.6JDK1.5 and JayBird2.1.6JDK1.6
and got the same result.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

assignee: Roman Rokytskyy [ rrokytskyy ] => Mark Rotteveel [ avalanche1979 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

I have not been able to reproduce this problem using Jaybird 2.1.6 or 2.2 (latest build), neither with Firebird 2.1.4 or 2.5. I do notice some weirdness in the way getSqlCounts goes through the info-buffer which might lead to an ArrayIndexOutOfBounds depending on the infobuffer content. I will need to investigate that further.

On further examination the codepath that throws the ArrayIndexOutOfBoundsException in the reproduction should never have been reached because the Exception for the primary key violation is thrown before that code is reached. I am not sure how that could happen in your case without Firebird not actually sending the error (or Jaybird not properly receiving the error).

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Closing this issue as I am not able to reproduce it.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Closed [ 6 ]

resolution: Cannot Reproduce [ 5 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants