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 ajoo <aj...@gmail.com> on 2007/01/06 17:29:57 UTC

NPE when using user connection and sub-select statement

Hi, our project uses ibatis in a slightly different way. The legacy system
uses a ConnectionManager to obtain and release connections. So I had to use
SqlMapClient.openSession(Connection).

Accordiing to the javadoc, when using openSession(Connection), I need to
manage transaction myself, which I did.

IBatis works fine with queryForObject and queryForList.

The problem occurs when I have a 1+N mapping (where a select statement is
specified to get a sub-object) in the mapping file. In this case, a
NullPointerException is thrown at line 780 of SqlMapExecutorDelegate class,
which calls txManager.end(session). The stack trace also shows that this
error occurs when iBatis is trying to call queryForList() when the lazily
loaded list is evaluated.

This leads me to suspect that iBatis knows not to do transaction when the
java code calls queryForList, but when it performs a 1+N mapping, it fails
to ignore transaction, hence caused NPE.

This is just my wild guess based on the symptom.

Currently we delete the 1+N mapping from the mapping file and do it with a
Java loop. It works fine.
-- 
View this message in context: http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8195657
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NPE when using user connection and sub-select statement

Posted by ajoo <aj...@gmail.com>.
Got it. It woks fine with my testing. Will do some more integrated test
before switching to this approach.

This wiki shows my solution in case anyone wants to know the details:
http://dimple.codehaus.org/Integrate+IBatis+With+Legacy+System

Ben.



Larry Meadors-2 wrote:
> 
> Yes, you will need both a DataSource and a DataSourceFactory, the
> complexity of the factory will depend completely on the complexity of
> your current connection manager.
> 
> Larry
> 
> 
> On 1/6/07, ajoo <aj...@gmail.com> wrote:
>>
>>
>>
>> Larry Meadors-2 wrote:
>> >
>> > I was in a similar position, but was able to make that "connection
>> > manager" look like a javax.sql.DataSource and use it that way with
>> > iBATIS.
>> >
>> > You should investigate doing that with yours - it's actually pretty
>> > simple, there are only 6 methods in the interface (well, a couple more
>> > with JDBC4, but you're probably not there yet).
>> >
>> > The chief advantage of doing that is that it will get you *completely*
>> > out of the connection management business - you can let iBATIS handle
>> > it all, which will VASTLY simplify your entire system.
>> >
>> > Larry
>> >
>>
>> Thanks Larry. I suppose you are talking about the DataSourceFactory
>> interface? I'll definitely give it a try. It sounds like many of my
>> ibatis
>> integration code can be go away this way, which will be great.
>>
>>
>> By the way, if you are concerned about versioning problem with
>> DataSource,
>> check out http://dimple.codehaus.org, it allows one to implement only the
>> relevant methods and leave the irrelevant UnsupportedOperationException.
>>
>> Ben
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8199910
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8206804
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NPE when using user connection and sub-select statement

Posted by Larry Meadors <lm...@apache.org>.
Yes, you will need both a DataSource and a DataSourceFactory, the
complexity of the factory will depend completely on the complexity of
your current connection manager.

Larry


On 1/6/07, ajoo <aj...@gmail.com> wrote:
>
>
>
> Larry Meadors-2 wrote:
> >
> > I was in a similar position, but was able to make that "connection
> > manager" look like a javax.sql.DataSource and use it that way with
> > iBATIS.
> >
> > You should investigate doing that with yours - it's actually pretty
> > simple, there are only 6 methods in the interface (well, a couple more
> > with JDBC4, but you're probably not there yet).
> >
> > The chief advantage of doing that is that it will get you *completely*
> > out of the connection management business - you can let iBATIS handle
> > it all, which will VASTLY simplify your entire system.
> >
> > Larry
> >
>
> Thanks Larry. I suppose you are talking about the DataSourceFactory
> interface? I'll definitely give it a try. It sounds like many of my ibatis
> integration code can be go away this way, which will be great.
>
>
> By the way, if you are concerned about versioning problem with DataSource,
> check out http://dimple.codehaus.org, it allows one to implement only the
> relevant methods and leave the irrelevant UnsupportedOperationException.
>
> Ben
>
>
> --
> View this message in context: http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8199910
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: NPE when using user connection and sub-select statement

Posted by ajoo <aj...@gmail.com>.


Larry Meadors-2 wrote:
> 
> I was in a similar position, but was able to make that "connection
> manager" look like a javax.sql.DataSource and use it that way with
> iBATIS.
> 
> You should investigate doing that with yours - it's actually pretty
> simple, there are only 6 methods in the interface (well, a couple more
> with JDBC4, but you're probably not there yet).
> 
> The chief advantage of doing that is that it will get you *completely*
> out of the connection management business - you can let iBATIS handle
> it all, which will VASTLY simplify your entire system.
> 
> Larry
> 

Thanks Larry. I suppose you are talking about the DataSourceFactory
interface? I'll definitely give it a try. It sounds like many of my ibatis
integration code can be go away this way, which will be great.


By the way, if you are concerned about versioning problem with DataSource,
check out http://dimple.codehaus.org, it allows one to implement only the
relevant methods and leave the irrelevant UnsupportedOperationException.

Ben


-- 
View this message in context: http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8199910
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NPE when using user connection and sub-select statement

Posted by Larry Meadors <lm...@apache.org>.
On 1/6/07, ajoo <aj...@gmail.com> wrote:
> Hi, our project uses ibatis in a slightly different way. The legacy system
> uses a ConnectionManager to obtain and release connections. So I had to use
> SqlMapClient.openSession(Connection).

I was in a similar position, but was able to make that "connection
manager" look like a javax.sql.DataSource and use it that way with
iBATIS.

You should investigate doing that with yours - it's actually pretty
simple, there are only 6 methods in the interface (well, a couple more
with JDBC4, but you're probably not there yet).

The chief advantage of doing that is that it will get you *completely*
out of the connection management business - you can let iBATIS handle
it all, which will VASTLY simplify your entire system.

Larry

Re: NPE when using user connection and sub-select statement

Posted by ajoo <aj...@gmail.com>.
BTW, we are using iBatis 2.2 for Java
-- 
View this message in context: http://www.nabble.com/NPE-when-using-user-connection-and-sub-select-statement-tf2931416.html#a8195681
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.