You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Sekar, Sowmya" <ss...@ucsd.edu> on 2008/10/28 23:37:19 UTC

DDL support from Ibatis

Hi,
I am trying to rename a table from ibatis.
                Try{
            String resource = "sql-map-config.xml";
            Reader reader = Resources.getResourceAsReader(resource);
            sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
            reader.close();
 
            sqlMap.update("table", null);
            sqlMap.startTransaction();
//code here
            sqlMap.commitTransaction();
      }
Catch(Exception e)
{
}
Finally{
      sqlMap.endTransaction();
}
 
Sql-map-config.xml :
EXEC sp_rename old_table, new_table
 
When I Execute this piece, it throws an exception :
 
--- Cause: com.sybase.jdbc2.jdbc.SybSQLException: Can't run sp_rename
from within a transaction.
 
What could be the problem?
Is DDL supported by Ibatis or not?
Sowmya Sekar
 

Re: DDL support from Ibatis

Posted by Clinton Begin <cl...@gmail.com>.
Getting rid of start/stop won't work, because iBATIS performs "autocommit"
within a transaction still.... :-)

So what you'll need to do is:

session = sqlMapClient.openSession(yourConnectionInAutoCommitMode);
session..... //do work
session.close();

Clinton

On Wed, Oct 29, 2008 at 10:44 AM, Jeff Butler <je...@gmail.com> wrote:

> DDL is not "officially" supported in iBATIS - for whatever that's
> worth.  But many people run DDL statements successfully.
>
> The problem seems obvious to me - Sybase does not allow DDL statements
> in transactions (this is true of many other databases also).  So you
> need to get rid of the startTransaction(), commitTransaction() calls.
> Also, I would suggest executing the DDL with the queryForObject()
> method so iBATIS won't wrap a transaction around the call.
>
> Jeff Butler
>
>
>
>
> On Tue, Oct 28, 2008 at 5:37 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
> > Hi,
> >
> > I am trying to rename a table from ibatis.
> >
> >                 Try{
> >
> >             String resource = "sql-map-config.xml";
> >
> >             Reader reader = Resources.getResourceAsReader(resource);
> >
> >             sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
> >
> >             reader.close();
> >
> >
> >
> >             sqlMap.update("table", null);
> >
> >             sqlMap.startTransaction();
> >
> > //code here
> >
> >             sqlMap.commitTransaction();
> >
> >       }
> >
> > Catch(Exception e)
> >
> > {
> >
> > }
> >
> > Finally{
> >
> >       sqlMap.endTransaction();
> >
> > }
> >
> >
> >
> > Sql-map-config.xml :
> >
> > EXEC sp_rename old_table, new_table
> >
> >
> >
> > When I Execute this piece, it throws an exception :
> >
> >
> >
> > --- Cause: com.sybase.jdbc2.jdbc.SybSQLException: Can't run sp_rename
> from
> > within a transaction.
> >
> >
> >
> > What could be the problem?
> >
> > Is DDL supported by Ibatis or not?
> >
> > Sowmya Sekar
> >
> >
>

Re: DDL support from Ibatis

Posted by Jeff Butler <je...@gmail.com>.
DDL is not "officially" supported in iBATIS - for whatever that's
worth.  But many people run DDL statements successfully.

The problem seems obvious to me - Sybase does not allow DDL statements
in transactions (this is true of many other databases also).  So you
need to get rid of the startTransaction(), commitTransaction() calls.
Also, I would suggest executing the DDL with the queryForObject()
method so iBATIS won't wrap a transaction around the call.

Jeff Butler




On Tue, Oct 28, 2008 at 5:37 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
> Hi,
>
> I am trying to rename a table from ibatis.
>
>                 Try{
>
>             String resource = "sql-map-config.xml";
>
>             Reader reader = Resources.getResourceAsReader(resource);
>
>             sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
>
>             reader.close();
>
>
>
>             sqlMap.update("table", null);
>
>             sqlMap.startTransaction();
>
> //code here
>
>             sqlMap.commitTransaction();
>
>       }
>
> Catch(Exception e)
>
> {
>
> }
>
> Finally{
>
>       sqlMap.endTransaction();
>
> }
>
>
>
> Sql-map-config.xml :
>
> EXEC sp_rename old_table, new_table
>
>
>
> When I Execute this piece, it throws an exception :
>
>
>
> --- Cause: com.sybase.jdbc2.jdbc.SybSQLException: Can't run sp_rename from
> within a transaction.
>
>
>
> What could be the problem?
>
> Is DDL supported by Ibatis or not?
>
> Sowmya Sekar
>
>