mssql2000 transaction problem
kmaes Feb 17, 2003 6:35 PMHi,
I got JBOSS 3.0.4 + latest castor-0.9.4.3... and the setup like the infamous "rooms2.zip" seems ok except for updates.
I always run into "Unable to commit" problem.
have a look at following simple example :
** READING FROM THE DATABASE WORKS FINE:
* @ejb.interface-method
* view-type="both"
* @ejb.transaction
* type="Required"
*
public Contact getContact(long contactId) throws ServerException{
Contact contact = null;
DataObjects _jdo;
Database db = null;
OQLQuery findOql;
QueryResults results;
Object data = null;
try {
InitialContext ic = new InitialContext();
_jdo = (DataObjects) ic.lookup("java:/jdo/CastorJDO");
db = _jdo.getDatabase();
findOql = db.getOQLQuery("Select c from be.domainnames.J2EEtest1.castor.Contact c where contactId = 81");
results=findOql.execute();
if ( results.hasMore() ) {
contact = (Contact)results.next();
}
} catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
finally {
try{
if(db!=null) db.close();
} catch(PersistenceException e) {
System.err.println("Could not close a database connection:"+e.getMessage());
e.printStackTrace(System.err);
}
}
return contact;
}
** UPDATING THE DATABASE DOES NOT WORK ??
* @ejb.interface-method
* view-type="both"
* @ejb.transaction
* type="Required"
*
public void updateContact(Contact contact) throws ServerException{
DataObjects _jdo;
Database db = null;
OQLQuery findOql;
QueryResults results;
Object data = null;
try {
InitialContext ic = new InitialContext();
_jdo = (DataObjects) ic.lookup("java:/jdo/CastorJDO");
db = _jdo.getDatabase();
db.update(contact);
} catch(Exception e){
System.out.println("ERROR UPDATING");
e.printStackTrace();
}
finally {
try{
if(db!=null) db.close();
} catch(PersistenceException e) {
System.err.println("Could not close a database connection:"+e.getMessage());
}
}
}
Then I always get :
12:17:40,868 ERROR [STDERR] java.lang.reflect.UndeclaredThrowableException
12:17:40,869 ERROR [STDERR] at $Proxy81.updateContact(Unknown Source)
................................
12:17:40,884 ERROR [STDERR] Caused by: javax.transaction.RollbackException: Unable to commit, tx=XidImpl [FormatId=257, GlobalId=barabas//67, BranchQual=] status=STATUS_ROLLEDBACK
12:17:40,885 ERROR [STDERR] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:425)
12:17:40,885 ERROR [STDERR] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:73)
12:17:40,885 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:201)
12:17:40,886 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
I am using MSSQL 2000 with the latest MS SQL drivers :
<?xml version = '1.0' encoding = 'UTF-8' ?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- ====================================================================== -->
<!-- New ConnectionManager setup for Microsoft SQL Server 2000 driver -->
<!-- You may download the latest Microsoft JDBC driver from *Microsoft* -->
<!-- http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml&frame=true -->
<!-- Build jmx-api (build/build.sh all) and view for config documentation -->
<!-- ===================================================================== -->
<!-- Include a login module configuration named MSSQLDbRealm.
Update your login-conf.xml, here is an example for a
ConfiguredIdentityLoginModule:
<application-policy name = "MSSQLDbRealm">
<login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
<module-option name = "principal">yourprincipal</module-option>
<module-option name = "userName">yourusername</module-option>
<module-option name = "password">yourpassword</module-option>
<module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
</login-module>
</application-policy>
NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
module-option name = "managedConnectionFactoryName"
must match the object name of the ConnectionManager you are configuring here.
-->
<!-- uncomment out this line if you are using the MSSQLDbRealm above
MSSQLDbRealm
-->
<depends optional-attribute-name="ManagedConnectionFactoryName">
<!-- embedded mbean -->
jdbc/MSSQLDS
<config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://lambik.kmoware.com:1433;DatabaseName=Development;SelectMethod=cursor</config-property>
<config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</config-property>
<!-- set these only if you want only default logins, not through JAAS -->
<config-property name="UserName" type="java.lang.String">sa</config-property>
<config-property name="Password" type="java.lang.String">********<config-property>
<!-- Below here are advanced properties -->
<!-- hack -->
<depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper
<depends optional-attribute-name="ManagedConnectionPool">
<!-- embedded mbean -->
0
50
5000
15
<!-- criteria indicates if Subject (from security domain) or app supplied
parameters (such as from getConnection(user, pw)) are used to distinguish
connections in the pool. Choices are
ByContainerAndApplication (use both),
ByContainer (use Subject),
ByApplication (use app supplied params only),
ByNothing (all connections are equivalent, usually if adapter supports
reauthentication) -->
ByContainer
<depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager
<depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager
java:/TransactionManager
<!-- make the rar deploy! hack till better deployment -->
jboss.jca:service=RARDeployer
Manually starting a transaction naturally says the transaction is already in progress.
I have no more clues............ any help very much appreciated.
brgds,
koen