Re: Simple example of N+1 selects

2005-01-28 Thread Kris Jenkins
Magnus Stattin wrote:
Hi
How would I be able to avoid the N+1 selects if I have for example a
departments table and a table with employees. All employees belongs to a
department and I would like to get a list of department valueObjects where
each departmentVo contains a collection of employee valueObjects. 

Is it possible to do this with a single select with Ibatis and how would the
Sqlmap look like. I am looking for a simple example to get me started.
Thank you 

Magnus
 

Take a look at this wiki FAQ:
http://wiki.apache.org/ibatis/How_20do_20I_20get_20around_20the_20n_2b1_20selects_20problem_3f
Kris

--
Kris Jenkins
Email:  [EMAIL PROTECTED]
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/


Feedback

2005-01-28 Thread Fabrizio Gianneschi
Hello all,

I write this mail to share with you all my satisfaction in using iBATIS.
The project I was working on until yesterday has been completed and
delivered perfectly in time.
Since it was a db-intensive web application (not much business logic, a lot
of queries, a not usual db configuration) I consider iBATIS as an important
factor that contributed to our success. Its use permitted us to be better
focused on other application aspects, with simple XML changes and without
recompiling the Java code.

THIS, is the way J2EE should take.

Thanks a lot, Clinton.
Thanks to all of the people that work on this great project.

Fabrizio Gianneschi
Italy



Re: a few questions

2005-01-28 Thread Larry Meadors
I cannot speak for the rest of the team, but if it were up to me,
probably not. :-/

Some of the most attractive things about iBATIS (for many users) are
simplicity, the fact that it does not mess with your SQL unless it is
absolutely neccessary, that it does not impose anything on your
development, and that it is not database specific.

Please do not take my comments the wrong way: I am not saying that
what you are asking for is of no value, but many of them go directly
against those points.

Creating DDL, is VERY database specific, especially when you start
talking about generating keys, datatypes, tablespaces, and so on. The
differences between Oracle, MySQL, and M$SQL alone would be
significant enough to eat up weeks of development time that could be
used to do other things.

The other two things on the list (3  4), IMO are more the domain of
the DAO or business logic layer.

But you may be able to convince me otherwise! I am not dead against us
doing that if we can do it in a way that meets the criteria above. :-)

One of the valuable things in iBATIS is that it is powerful, yet
constructed in such a way that you can leverage it without becoming
married to it. Let me see if I can explain that in a way that makes
sense.

Before using iBATIS, I used Hibernate. It sounded great - it was very
powerful and did many of the things you described above. It would
generate DDL, do optimistic locking, and inserts like you described
worked. But, the problem was that I had to define my database
according to Hibernate's rules. I also needed to have a stateful
environment to keep persisted objects in to keep them fresh for
Hibernate. I also had to implement Hibernate specific interfaces in my
code to make certain features work. Pretty soon, I was not writing
applications according to the standards of the company I worked for,
but instead, according to the standards of Hibernate. That (to me) is
an anti-pattern called Vendor Lock-in, and to be avoided.

Now, I use iBATIS. My applications could not care less that I am using
iBATIS, because the only part that has to be aware of it is the DAO
layer. Yes, I have to implement the audit trail, and optimistic
locking on my own, but, if I want to use another DAO implementation, I
can.

Larry

On Fri, 28 Jan 2005 11:02:06 +0800, Nathan Coast [EMAIL PROTECTED] wrote:
 great, thanks for the quick response,  its pretty much as I figured when
 I couldn't find anything covering these in the docs.  Do you know if
 there is any support for these features planned in future releases?
 
 Larry Meadors wrote:
  1) No.
 
  2) Yes, you can do that for either auto-generated or assigned keys.
 
  3) No.
 
  4) No.
 
  That said, 3  4 can be pretty simple to build, depending on how
  intricate you want to get with them.
 
  Larry
 
  On Fri, 28 Jan 2005 10:16:42 +0800, Nathan Coast [EMAIL PROTECTED] wrote:
 
 1) ddl - is it possible to define your table structures in ibatis and
 have ibatis create the tables?
 
 2) inserts - is the primary key retuned for all calls to the
 SqlMapExecutor.insert method.  I have only seen examples in the docs for
 inserts that require a selectKey (oracle, ms sql server) what about
 auto generated keys (e.g. mysql)?
 
 3) optimistic locking - is there any declarative support for optimistic
 locking - e.g. having a last_modified column in the db / object throw an
 error during the update method if the last mod in the value is different
 from the db.
 
 4) audit trail - 4 cols: created_by, created_timestamp, modified_by,
 modified_timestamp. again updated by the framework during insert, update
 statements.  would require some form of authentication (jaas) from the
 enclosing container.  I'm guessing the majority of apps run in one
 container or another tomcat, jboss etc so should be possible.
 
 Just trying to get a feel for what we'd get for free, what we'd have to
 build and what may be coming soon.
 
 
 
 
 --
 Nathan Coast
 Managing Director
 Codeczar Ltd
 mob : (852) 9049 5581
 tel : (852) 2834 8733
 fax : (852) 2834 8755
 web : http://www.codeczar.com



Re: One DAO implementatino for multiple databases

2005-01-28 Thread Brandon Goodin
You can only declare a single Dao implementation per DaoManager. This
is due to the fact that the Dao interface name is used as the key to
lookup the implementation. I think the easiest route for you may be to
extend the interface of your Daos interfaces that are shared. That way
you will have a unique interface for each yet they can have the same
implementation class.

Brandon

On Thu, 27 Jan 2005 15:04:52 -0800, Tony Li [EMAIL PROTECTED] wrote:
  
  
 
 Hi all  
 
   
 
 I'm new to iBatis, and I want to find out the best practice for this
 problem.  I want to use the same DAO implementation on a number of different
 databases.  I'm pulling in data from an MS Access database (yes, please feel
 sorry for me here) that's been deployed in several locations.  I'm using the
 both the iBATIS DAO layer and SqlMaps.  Since I declare a DAO implementation
 under a specific Transaction Manager, and only one DataSource can be
 specified per transaction, I'm not sure what to do.  If I define the same
 DAO implementation under a different Transaction Manager and Context, how
 would iBatis know which one to use when I ask for the DAO from the
 DaoManager? 
 
   
 
 Any suggestions? 
 
   
 
 Thanks, 
 
 Tony 
 



Re: Two separate map configs

2005-01-28 Thread Larry Meadors
Nah, DAO is super simple to use.

http://reumann.net/struts/ibatisLesson1.do

This covers an older version, but the one and two are very similar.

Larry


On Fri, 28 Jan 2005 10:23:23 -0500, Akins, Greg [EMAIL PROTECTED] wrote:
 To be honest I was intimidated by learning that.
 
 I had used Hibernate; so apart from getting up to speed on Ibatis; at
 least I was familiar with Persistence layers..
 
 However, I haven't used a DAO framework and am concerned that I won't be
 able to get up to speed quickly enough.
 
 -Original Message-
 From: Brandon Goodin [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 28, 2005 10:11 AM
 To: ibatis-user-java@incubator.apache.org
 Subject: Re: Two separate map configs
 
 
 yeah... use the DAO framework. :D
 
 On Thu, 27 Jan 2005 16:55:56 -0500, Akins, Greg [EMAIL PROTECTED]
 wrote:
  OK, I stripped out my DAO objects for the second mapping (and the old
  tests; and the new tests work... ) leading me to believe that I have
  not reset an instance of SqlMapClient.
 
  I'll have to rewrite my DAO super classes... Can anyone point me to a
  good pattern for constructing those (since mine obviously sucked:')
 
  Thanks for the pointers.
 
  -Original Message-
  From: Clinton Begin [mailto:[EMAIL PROTECTED]
  Sent: Thursday, January 27, 2005 2:12 PM
  To: Akins, Greg
  Cc: ibatis-user-java@incubator.apache.org
  Subject: Re: Two separate map configs
 
  Greg,
 
  Do you have two SqlMapClient instances?  (you should)
 
  Cheers,
  Clinton
 
  On Thu, 27 Jan 2005 13:55:53 -0500, Akins, Greg [EMAIL PROTECTED]
  wrote:
   Thanks... I'm not getting any other errors when I run this.  I can
   post the rest of the code, but basically I'm Querying by calling
  
   Object prod = sqlMap.queryForObject(getWare, srchObj.getName()) ;
  
   And am getting this stacktrace from my tests.
  
   com.ibatis.sqlmap.client.SqlMapException: There is no statement
   named getWare in this SqlMap.
   at
   com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getMappedStatem
   en
   t(
   SqlMapExecutorDelegate.java:288)
   at
  
  com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(Sq
  lM
   apExecutorDelegate.java:552)
   at
  
  com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(Sq
  lM
   apExecutorDelegate.java:536)
   at
  
  com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapS
  es
   sionImpl.java:97)
   at
  
  com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapCl
  ie
   ntImpl.java:69)
   at
   com.amervideo.ehold.dao.MesBaseDAO.getObject(MesBaseDAO.java:68)
   at
   com.amervideo.ehold.dao.WareDAO.getObjectByName(WareDAO.java:22)
   at eHoldTest.TestWareDAO.testGetWare(TestWareDAO.java:39)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
 Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
 Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
   Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at
  junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at
  
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remote
  Te
   stRunner.java:421)
   at
  
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestR
  un
   ner.java:305)
   at
  
  org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTest
  Ru
   nner.java:186)
  
   SqlMapsMES.xml
   
   ?xml version=1.0 encoding=UTF-8?
  
   !DOCTYPE sqlMapConfig
   PUBLIC -//iBATIS.com//DTD SQL Map Config  2.0//EN
   http://www.ibatis.com/dtd/sql-map-config-2.dtd;
  
   sqlMapConfig
  
   properties resource=mesDb.properties /
   transactionManager type=JDBC 
   dataSource type=SIMPLE 
   property name=JDBC.Driver
   value=${driver}/
   property name=JDBC.ConnectionURL
   value=${url}/
   property name=JDBC.Username
   value=${username}/
   property name=JDBC.Password
   value=${password}/
   /dataSource
   /transactionManager
  
   sqlMap resource=com/amervideo/ehold/sql/MoldSQL.xml /
   sqlMap resource=com/amervideo/ehold/sql/WareSQL.xml /
  
   /sqlMapConfig
  
   WareSQL.xml
   
   ?xml version=1.0 encoding=UTF-8 ?
   !DOCTYPE sqlMap PUBLIC -//iBatis.com//DTD SQL Map 2.0//EN
   

Re: Feedback

2005-01-28 Thread Brandon Goodin
should we put these feedback on the wiki. It would be great to record
successful experiences with IBatis.


On Fri, 28 Jan 2005 10:50:22 +0100, Fabrizio Gianneschi
[EMAIL PROTECTED] wrote:
 Hello all,
 
 I write this mail to share with you all my satisfaction in using iBATIS.
 The project I was working on until yesterday has been completed and
 delivered perfectly in time.
 Since it was a db-intensive web application (not much business logic, a lot
 of queries, a not usual db configuration) I consider iBATIS as an important
 factor that contributed to our success. Its use permitted us to be better
 focused on other application aspects, with simple XML changes and without
 recompiling the Java code.
 
 THIS, is the way J2EE should take.
 
 Thanks a lot, Clinton.
 Thanks to all of the people that work on this great project.
 
 Fabrizio Gianneschi
 Italy
 



Re: Mapping an Oracle CHAR(1) column to java char property

2005-01-28 Thread Clinton Begin
Chars haven't been supported to date, because JDBC does not support
them.  However, I suppose there's no reason why you couldn't build a
custom type handler for that

Clinton


On Fri, 28 Jan 2005 11:07:08 +1300, Stephen Chell (DSL AK)
[EMAIL PROTECTED] wrote:
 Hi,
 
 I'm having trouble mapping an oracle CHAR(1) column to a javabeans
 property that is of type char.  I'm using SQL Maps 2.0.9 with Spring
 1.1.3.
 
 Here is my resultMap (defined in the mapping file ChargeType.xml):
 
 resultMap id=result
 class=nz.ac.otago.its.chargeadmin.domain.ChargeType
 result property=code column=CHARGE_TYPE_CODE
 columnIndex=1/
 result property=narration column=NARRATION
 columnIndex=2/
 result property=status column=STATUS columnIndex=3/
 result property=versionNo column=VERSION_NO
 columnIndex=4/
 result property=versionDateTime column=VERSION_DATE_TIME
 columnIndex=5/
 result property=versionUser column=VERSION_USER
 columnIndex=6/
 /resultMap
 
 The offending column is the status column, which is a CHAR(1) in Oracle
 and a char property in the ChargeType class.   When I try to execute a
 query that uses this result map, the following exception occurs:
 
 org.springframework.jdbc.UncategorizedSQLException: (SqlMapClient
 operation): encountered SQLException [
 --- The error occurred in
 nz/ac/otago/its/chargeadmin/dao/ibatis/maps/ChargeType.xml.
 --- The error occurred while applying a result map.
 --- Check the ChargeType.result.
 --- Check the result mapping for the 'status' property.
 --- Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler
 could be found to map the property 'status' to the column 'STATUS'.  One
 or both of the types, or the combination of types is not supported.];
 nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
 
 --- The error occurred in
 nz/ac/otago/its/chargeadmin/dao/ibatis/maps/ChargeType.xml.
 --- The error occurred while applying a result map.
 --- Check the ChargeType.result.
 --- Check the result mapping for the 'status' property.
 --- Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler
 could be found to map the property 'status' to the column 'STATUS'.  One
 or both of the types, or the combination of types is not supported.
 com.ibatis.common.jdbc.exception.NestedSQLException:
 --- The error occurred in
 nz/ac/otago/its/chargeadmin/dao/ibatis/maps/ChargeType.xml.
 --- The error occurred while applying a result map.
 --- Check the ChargeType.result.
 --- Check the result mapping for the 'status' property.
 --- Cause: com.ibatis.sqlmap.client.SqlMapException: No type handler
 could be found to map the property 'status' to the column 'STATUS'.  One
 or both of the types, or the combination of types is not
 supported.Caused by: com.ibatis.sqlmap.client.SqlMapException: No type
 handler could be found to map the property 'status' to the column
 'STATUS'.  One or both of the types, or the combination of types is not
 supported.
 at
 com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
 WithCallback(GeneralStatement.java:183)
 at
 com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQuery
 ForList(GeneralStatement.java:118)
 at
 com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
 ExecutorDelegate.java:610)
 at
 com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMap
 ExecutorDelegate.java:584)
 at
 com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessi
 onImpl.java:105)
 at
 org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(S
 qlMapClientTemplate.java:202)
 at
 org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClient
 Template.java:142)
 at
 org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResul
 t(SqlMapClientTemplate.java:164)
 at
 org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapC
 lientTemplate.java:200)
 at
 nz.ac.otago.its.chargeadmin.dao.ibatis.SqlMapChargeTypeDao.getChargeType
 List(SqlMapChargeTypeDao.java:22)
   [etc]
 
 Explicity specifing the type of the status property in the result
 element using the javaType and/or jdbcType attributes doesn't help.  I
 tried all of the following combinations:
 
 result property=status column=STATUS columnIndex=3
 javaType=char/
 result property=status column=STATUS columnIndex=3
 javaType=java.lang.Character/
 result property=status column=STATUS columnIndex=3
 jdbcType=CHAR/
 result property=status column=STATUS columnIndex=3
 javaType=char jdbcType=CHAR/
 result property=status column=STATUS columnIndex=3
 javaType=java.lang.Character jdbcType=CHAR/
 
 None of these work, although the exception when specifying
 javaType=char is different, as shown below.
 
 What am I doing wrong?
 
 Thanks in advance
 
 Steve
 
 

A question about nullValue in resultMap.

2005-01-28 Thread Bing Zou
Hi,

So far in iBbatis, when the parameter of the result Bean's setter is
primitive type (for example, setParentCategoryID(long id)),  if the
corresponding column might get a database NULL value during execution,
we have at least three solutions:
1. Change the Bean's setter to use Object type parameter instead of
primitive type. (for example, use setParentCategoryID(Long id_object)
instead).
2. Use ResultMap and specify nullValue of the nullable property.
3. Use ResultMap and specify TypeHandler to take care of the returned
Null value.

Obviously solution 1 is not a good one while solution 2 and 3 require
using ResultMap instead of using ResultClass directly.

Now the question is, I want to keep the sqlmap xml file as simple as
possible, so I want to use as much implicit result mapping as
possible. (Because using resultMap will make the xml file a little bit
harder to read, understand, debug and maintain.) I want to avoid
ResultMap even there is nullable column in the SQL statement. So I
hope iBatis could take care of the null values for me.

I am wondering whether the iBatis team will consider adding one more
property to the iBatis configuration file like SkipSettingNullResult.
If SkipSettingNullResult=true, while iBatis sees a Null value returned
from the resultSet, if the corresponding setter is taking a primitive
type parameter, iBatis simply skip this setter and the Bean will use
the default value instead of executing the setter.

I will sincerely appreciate it if the iBatis team could make it happen
in the near future.

Thanks a lot.
Bing


Re: A question about nullValue in resultMap.

2005-01-28 Thread Larry Meadors
Just curious: If you can have null values, why are you using primitive
values. You do realize that even if we do not call the setter, the
property holder will be set to 0 anyway, right?

public class MyBean{
  int myProp; // -- since this MUST be initialized, the JVM sets it to 0
  public int getMyProp(){
return myProp;
  }
  public void setMyProp(int val){
myProp = val;
  }
  public static void main(String[] a){
MyBean myBean = new MyBean();
System.out.println(myBean.getMyProp()); // -- will be 0
  }
}

So, do you have some other logig in your setter or something that
detects if it was called, or is there some other compelling reason for
this? IMO, it seems silly.

Larry

On Fri, 28 Jan 2005 15:10:19 -0500, Bing Zou [EMAIL PROTECTED] wrote:
 Hi,
 
 So far in iBbatis, when the parameter of the result Bean's setter is
 primitive type (for example, setParentCategoryID(long id)),  if the
 corresponding column might get a database NULL value during execution,
 we have at least three solutions:
 1. Change the Bean's setter to use Object type parameter instead of
 primitive type. (for example, use setParentCategoryID(Long id_object)
 instead).
 2. Use ResultMap and specify nullValue of the nullable property.
 3. Use ResultMap and specify TypeHandler to take care of the returned
 Null value.
 
 Obviously solution 1 is not a good one while solution 2 and 3 require
 using ResultMap instead of using ResultClass directly.
 
 Now the question is, I want to keep the sqlmap xml file as simple as
 possible, so I want to use as much implicit result mapping as
 possible. (Because using resultMap will make the xml file a little bit
 harder to read, understand, debug and maintain.) I want to avoid
 ResultMap even there is nullable column in the SQL statement. So I
 hope iBatis could take care of the null values for me.
 
 I am wondering whether the iBatis team will consider adding one more
 property to the iBatis configuration file like SkipSettingNullResult.
 If SkipSettingNullResult=true, while iBatis sees a Null value returned
 from the resultSet, if the corresponding setter is taking a primitive
 type parameter, iBatis simply skip this setter and the Bean will use
 the default value instead of executing the setter.
 
 I will sincerely appreciate it if the iBatis team could make it happen
 in the near future.
 
 Thanks a lot.
 Bing



jpetstore: port to UNIX?

2005-01-28 Thread Ken Simpson
Hi - has anyone ported JPetStore 4 to MySQL 4.1.x and Tomcat 5.5.4 under UNIX 
- from whence it came?

It appears to be a question of using the case on the SQL commands consistently. 

For instance, the MySQL schema creates a database 'JPETSTORE' with upper case, 
and the 'account' table and columns with lower case

create table account (
userid varchar(80) not null,
email varchar(80) not null,
firstname varchar(80) not null,
lastname varchar(80) not null,
status varchar(2)  null,
addr1 varchar(80) not null,
addr2 varchar(40) null,
city varchar(80) not  null,
state varchar(80) not null,
zip varchar(20) not null,
country varchar(20) not null,
phone varchar(80) not null,
constraint pk_account primary key (userid)
);


but the sqlmapdao generates a mapping for upper case column names

sqlMap namespace=Account
typeAlias alias=account 
type=com.ibatis.jpetstore.domain.Account/
resultMap id=accountResult class=account
result property=username column=USERID/
result property=email column=EMAIL/
result property=firstName column=FIRSTNAME/
result property=lastName column=LASTNAME/
result property=status column=STATUS/
result property=address1 column=ADDR1/
result property=address2 column=ADDR2/
result property=city column=CITY/
result property=state column=STATE/
result property=zip column=ZIP/
result property=country column=COUNTRY/
result property=phone column=PHONE/
result property=languagePreference column=LANGPREF/
result property=favouriteCategoryId column=FAVCATEGORY /
result property=listOption column=MYLISTOPT /
result property=bannerOption column=BANNEROPT /
result property=bannerName column=BANNERNAME /
/resultMap

[snip]

-- Ken



WebSphere 5.1.X -- LocalTransaction rolled-back due to setRollbackOnly

2005-01-28 Thread Mark Nabours
Hello.

We are currently developing our first application with iBATIS, and we are extremely impressed by its design and capabilities. Everything was going great until we deployed our application to WAS 5.1 utilizing a JNDI datasource.

We end up receiving the following exception:
[1/28/05 20:31:45:954 CST] 796d3dfd WebGroup E SRVE0026E: [Servlet Error]-[LocalTransaction rolled-back due to setRollbackOnly]: com.ibm.ws.LocalTransaction.RolledbackException

I've read the following post concerning issues with WebSphere:
http://wiki.apache.org/ibatis/Database_20Specific_20Information

But I'm afraid that we cannot implement the suggestions since we externally acquire a connection and pass it to the SqlMapClient. Therefore, I'm not sure how or if we can set atransactionManager element within our configuration file since it requires a dataSource element as a child. Currently, we do not have a transactionManager element at all. 

Here is the code we use to pass the connection (sorry about the formatting -- I'm using a web-based e-mail editor):

/**
* Returns the cached code[EMAIL PROTECTED] SqlMapClient}/code instance for the DataSource alias. 
*/
protected SqlMapClient getSqlMapClient(String dataSourceAlias)
throws SQLException {

try {

SqlMapClient sqlMapClient =
IBatisSqlMapService.getInstance().getSqlMapClient(
dataSourceAlias);
if (sqlMapClient.getCurrentConnection() == null) {
//try to acquire a Connection from the abstract broker
try {

Connection connection =
getDatabaseConnection(dataSourceAlias);
if (connection != null) {
sqlMapClient.setUserConnection(connection);
logger.debug(
"Connection set via Common Services for \""
+ dataSourceAlias
+ "\".");
} else {
logger.debug(
"Connection not configured via Common Services for \""
+ dataSourceAlias
+ "\". Assuming iBatis will supply connection.");
}
} catch (SQLException e) {

logger.debug(
"Connection not configured via Common Services for \""
+ dataSourceAlias
+ "\". Assuming iBatis will supply connection.");
}
}
return sqlMapClient;
} catch (IOException e) {
throw new Error(e);
}
}

Also we "clean up" the application supplied user connection with the following code:

/**
* Clear out the code[EMAIL PROTECTED] Connection}/code instanced stored by this thread's
* code[EMAIL PROTECTED] SqlMapClient}/code instance keyed by codedataSourceName/code. 
*/
public void closeConnection(String dataSourceName) throws SQLException {
try {
//clear out user connection on sql map

SqlMapClient sqlMapClient =
IBatisSqlMapService.getInstance().getSqlMapClient(dataSourceName);
if (sqlMapClient != null) {

//explicitly commit transaction prior to close
Connection connection = sqlMapClient.getCurrentConnection();
if (connection != null) {

//attempt to prevent exception -- didn't work
connection.commit();
} 
sqlMapClient.setUserConnection(null);
logger.debug(
"The transaction for SqlMapClient \""
+ dataSourceName
+ "\" has been cleared for calling thread.");
}
//close connection
super.closeConnection(dataSourceName);
} catch (IOException e) {

throw new Error(e.getMessage());
}
}

The IBatisSqlMapService is a singleton that caches SQLMapClients.

I would appreciate any advice about how I could prevent the exception from occurring. Does iBATIS take part in transactions even if the connection is supplied externally? I'm also aware that the issue could be with our configuration of WebSphere, but I would like some ideas before I approach our WebSphere administrator.

Thanks,
Mark__Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com 

Re: WebSphere 5.1.X -- LocalTransaction rolled-back due to setRollbackOnly

2005-01-28 Thread Clinton Begin
Please set transactionManagercommitRequired=true

More info is available in the following poorly titled wiki (my fault):

http://wiki.apache.org/ibatis/Database_20Specific_20Information

Clinton


On Fri, 28 Jan 2005 19:09:29 -0800 (PST), Mark Nabours
[EMAIL PROTECTED] wrote:
 
 
 Hello. 
 
   
 
 We are currently developing our first application with iBATIS, and we are
 extremely impressed by its design and capabilities.  Everything was going
 great until we deployed our application to WAS 5.1 utilizing a JNDI
 datasource. 
 
   
 
 We end up receiving the following exception: 
 
 [1/28/05 20:31:45:954 CST] 796d3dfd WebGroup E SRVE0026E: [Servlet
 Error]-[LocalTransaction rolled-back due to setRollbackOnly]:
 com.ibm.ws.LocalTransaction.RolledbackException 
 
   
 
 I've read the following post concerning issues with WebSphere: 
 
 http://wiki.apache.org/ibatis/Database_20Specific_20Information 
 
   
 
 But I'm afraid that we cannot implement the suggestions since we externally
 acquire a connection and pass it to the SqlMapClient.  Therefore, I'm not
 sure how or if we can set a transactionManager element within our
 configuration file since it requires a dataSource element as a child. 
 Currently, we do not have a transactionManager element at all.  
 
   
 
 Here is the code we use to pass the connection (sorry about the formatting
 -- I'm using a web-based e-mail editor) : 
 
   
 
 /** 
 
 * Returns the cached code[EMAIL PROTECTED] SqlMapClient}/code instance 
 for the
 DataSource alias. 
 
 */ 
 
 protected SqlMapClient getSqlMapClient(String dataSourceAlias) 
 
 throws SQLException { 
  
 
 try { 
  
 
 SqlMapClient sqlMapClient = 
 
 IBatisSqlMapService.getInstance().getSqlMapClient( 
 
 dataSourceAlias); 
 
 if (sqlMapClient.getCurrentConnection() == null) { 
 
 //try to acquire a Connection from the abstract broker 
 
 try { 
  
 
 Connection connection = 
 
 getDatabaseConnection(dataSourceAlias); 
 
 if (connection != null) { 
 
 sqlMapClient.setUserConnection(connection); 
 
 logger.debug( 
 
 Connection set via Common Services for \ 
 
 + dataSourceAlias 
 
 + \.); 
 
 } else { 
 
 logger.debug( 
 
 Connection not configured via Common Services for \ 
 
 + dataSourceAlias 
 
 + \. Assuming iBatis will supply connection.); 
 
 } 
 
 } catch (SQLException e) { 
  
 
 logger.debug( 
 
 Connection not configured via Common Services for \ 
 
 + dataSourceAlias 
 
 + \. Assuming iBatis will supply connection.); 
 
 } 
 
 } 
 
 return sqlMapClient; 
 
 } catch (IOException e) { 
 
 throw new Error(e); 
 
 } 
 
 } 
 
   
 
 Also we clean up the application supplied user connection with the
 following code: 
 
   
 
 /** 
 
 * Clear out the code[EMAIL PROTECTED] Connection}/code instanced stored 
 by this
 thread's 
 
 * code[EMAIL PROTECTED] SqlMapClient}/code instance keyed by
 codedataSourceName/code. 
 
 */ 
 
 public void closeConnection(String dataSourceName) throws SQLException { 
 
 try { 
 
 //clear out user connection on sql map 
  
 
 SqlMapClient sqlMapClient = 
 
 IBatisSqlMapService.getInstance().getSqlMapClient(dataSourceName); 
 
 if (sqlMapClient != null) { 
  
 
 //explicitly commit transaction prior to close 
 
 Connection connection = sqlMapClient.getCurrentConnection(); 
 
 if (connection != null) { 
  
 
 //attempt to prevent exception -- didn't work 
 
 connection.commit(); 
 
 } 
 
 sqlMapClient.setUserConnection(null); 
 
 logger.debug( 
 
 The transaction for SqlMapClient \ 
 
 + dataSourceName 
 
 + \ has been cleared for calling thread.); 
 
 } 
 
 //close connection 
 
 super.closeConnection(dataSourceName); 
 
 } catch (IOException e) { 
  
 
 throw new Error(e.getMessage()); 
 
 } 
 
 } 
 
   
 
 The IBatisSqlMapService is a singleton that caches SQLMapClients. 
 
   
 
 I would appreciate any advice about how I could prevent the exception from
 occurring.  Does iBATIS take part in transactions even if the connection is
 supplied externally?  I'm also aware that the issue could be with our
 configuration of WebSphere, but I would like some ideas before I approach
 our WebSphere administrator. 
 
   
 
 Thanks, 
 
 Mark
 
 __
 Do You Yahoo!?
 Tired of spam? Yahoo! Mail has the best spam protection around 
 http://mail.yahoo.com


Re: Feedback

2005-01-28 Thread Clinton Begin
That's a SUPER idea Brandon.  Because we often get requests for 
feedback from other users.

Go for it bud!


Clinton

On Fri, 28 Jan 2005 08:31:01 -0700, Brandon Goodin
[EMAIL PROTECTED] wrote:
 should we put these feedback on the wiki. It would be great to record
 successful experiences with IBatis.
 
 On Fri, 28 Jan 2005 10:50:22 +0100, Fabrizio Gianneschi
 [EMAIL PROTECTED] wrote:
  Hello all,
 
  I write this mail to share with you all my satisfaction in using iBATIS.
  The project I was working on until yesterday has been completed and
  delivered perfectly in time.
  Since it was a db-intensive web application (not much business logic, a lot
  of queries, a not usual db configuration) I consider iBATIS as an important
  factor that contributed to our success. Its use permitted us to be better
  focused on other application aspects, with simple XML changes and without
  recompiling the Java code.
 
  THIS, is the way J2EE should take.
 
  Thanks a lot, Clinton.
  Thanks to all of the people that work on this great project.
 
  Fabrizio Gianneschi
  Italy