mybatis-guice: custom TypeHandler works only halfway

classic Classic list List threaded Threaded
74 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich

I am using a custom TypeHandler for conversion to/from Joda Time LocalDate class.

That type handler works fine in an application using “pure” mybatis (with my own very thin Seam layer).

However with mybatis-guice the type handler only works for writing to the DB. On reading I only ever get null’s.

 

I have tried to debug the problem, and it seems to me that mappers are registered/built before type handlers,

so the ResultMapping that is used when reading the property has a null typeHandler.

 

As a fix I changed ConfigurationProvider: After moving the lines containing the method registerTypeHandler

in front of the registerMappers method it starts to work.

 

However I am not sure if that relies on an implementation detail of Guice: Is the order of calls to @Inject

methods specified?

 

-- Stephen

 

Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
Hi Stephen,
good catch!!! Unfortunately Guice doesn't have an option to specify
the @Inject order, and AFAIK relies on methods order declaration.
If you would like to provide a patch I'd be more than pleased to apply
it and release soon an RC2 with this fix.
Thanks in advance, have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
<[hidden email]> wrote:

> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
> class.
>
> That type handler works fine in an application using “pure” mybatis (with my
> own very thin Seam layer).
>
> However with mybatis-guice the type handler only works for writing to the
> DB. On reading I only ever get null’s.
>
>
>
> I have tried to debug the problem, and it seems to me that mappers are
> registered/built before type handlers,
>
> so the ResultMapping that is used when reading the property has a null
> typeHandler.
>
>
>
> As a fix I changed ConfigurationProvider: After moving the lines containing
> the method registerTypeHandler
>
> in front of the registerMappers method it starts to work.
>
>
>
> However I am not sure if that relies on an implementation detail of Guice:
> Is the order of calls to @Inject
>
> methods specified?
>
>
>
> -- Stephen
>
>
Reply | Threaded
Open this post in threaded view
|

AW: mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich
Thanks, I have been busy hunting down a memory leak.
I can re-deploy my app to Tomcat 6 only a couple of times before the PermGen is full.

Turns out part of that is mybatis-guice fault, too:
In the ConfigurationProvide a thread local ErrorContext is implicitly created and never removed.

I'll go on and create a patch now for both problems.
I think the best thing to do is to create a guice InjectionListener for ConfigurationProvider,
move all the initialization stuff into afterInjection() and call ErrorContext.instance().reset()
at the end.

-- Stephen


-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
Gesendet: Sonntag, 12. September 2010 21:10
An: [hidden email]
Betreff: Re: mybatis-guice: custom TypeHandler works only halfway

Hi Stephen,
good catch!!! Unfortunately Guice doesn't have an option to specify
the @Inject order, and AFAIK relies on methods order declaration.
If you would like to provide a patch I'd be more than pleased to apply
it and release soon an RC2 with this fix.
Thanks in advance, have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
<[hidden email]> wrote:

> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
> class.
>
> That type handler works fine in an application using “pure” mybatis (with my
> own very thin Seam layer).
>
> However with mybatis-guice the type handler only works for writing to the
> DB. On reading I only ever get null’s.
>
>
>
> I have tried to debug the problem, and it seems to me that mappers are
> registered/built before type handlers,
>
> so the ResultMapping that is used when reading the property has a null
> typeHandler.
>
>
>
> As a fix I changed ConfigurationProvider: After moving the lines containing
> the method registerTypeHandler
>
> in front of the registerMappers method it starts to work.
>
>
>
> However I am not sure if that relies on an implementation detail of Guice:
> Is the order of calls to @Inject
>
> methods specified?
>
>
>
> -- Stephen
>
>
Reply | Threaded
Open this post in threaded view
|

AW: mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich
In reply to this post by Simone Tripodi
Hi Simo,

finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.

-- Stephen


-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
Gesendet: Sonntag, 12. September 2010 21:10
An: [hidden email]
Betreff: Re: mybatis-guice: custom TypeHandler works only halfway

Hi Stephen,
good catch!!! Unfortunately Guice doesn't have an option to specify
the @Inject order, and AFAIK relies on methods order declaration.
If you would like to provide a patch I'd be more than pleased to apply
it and release soon an RC2 with this fix.
Thanks in advance, have a nice day,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
<[hidden email]> wrote:

> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
> class.
>
> That type handler works fine in an application using “pure” mybatis (with my
> own very thin Seam layer).
>
> However with mybatis-guice the type handler only works for writing to the
> DB. On reading I only ever get null’s.
>
>
>
> I have tried to debug the problem, and it seems to me that mappers are
> registered/built before type handlers,
>
> so the ResultMapping that is used when reading the property has a null
> typeHandler.
>
>
>
> As a fix I changed ConfigurationProvider: After moving the lines containing
> the method registerTypeHandler
>
> in front of the registerMappers method it starts to work.
>
>
>
> However I am not sure if that relies on an implementation detail of Guice:
> Is the order of calls to @Inject
>
> methods specified?
>
>
>
> -- Stephen
>
>

configuration-provider.patch (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
You rock Stephen,
thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
Alles gute!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
<[hidden email]> wrote:

> Hi Simo,
>
> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>
> -- Stephen
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Sonntag, 12. September 2010 21:10
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> Hi Stephen,
> good catch!!! Unfortunately Guice doesn't have an option to specify
> the @Inject order, and AFAIK relies on methods order declaration.
> If you would like to provide a patch I'd be more than pleased to apply
> it and release soon an RC2 with this fix.
> Thanks in advance, have a nice day,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
> <[hidden email]> wrote:
>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>> class.
>>
>> That type handler works fine in an application using “pure” mybatis (with my
>> own very thin Seam layer).
>>
>> However with mybatis-guice the type handler only works for writing to the
>> DB. On reading I only ever get null’s.
>>
>>
>>
>> I have tried to debug the problem, and it seems to me that mappers are
>> registered/built before type handlers,
>>
>> so the ResultMapping that is used when reading the property has a null
>> typeHandler.
>>
>>
>>
>> As a fix I changed ConfigurationProvider: After moving the lines containing
>> the method registerTypeHandler
>>
>> in front of the registerMappers method it starts to work.
>>
>>
>>
>> However I am not sure if that relies on an implementation detail of Guice:
>> Is the order of calls to @Inject
>>
>> methods specified?
>>
>>
>>
>> -- Stephen
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

AW: mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich
Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
On second thought the call to ErrorContext.release() should better be in a finally block, right?
(Just in case an exception occurs during configuration after the ErrorContext has already been created).

-- Stephen

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
Gesendet: Mittwoch, 15. September 2010 09:19
An: [hidden email]
Betreff: Re: mybatis-guice: custom TypeHandler works only halfway

You rock Stephen,
thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
Alles gute!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
<[hidden email]> wrote:

> Hi Simo,
>
> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>
> -- Stephen
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Sonntag, 12. September 2010 21:10
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> Hi Stephen,
> good catch!!! Unfortunately Guice doesn't have an option to specify
> the @Inject order, and AFAIK relies on methods order declaration.
> If you would like to provide a patch I'd be more than pleased to apply
> it and release soon an RC2 with this fix.
> Thanks in advance, have a nice day,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
> <[hidden email]> wrote:
>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>> class.
>>
>> That type handler works fine in an application using “pure” mybatis (with my
>> own very thin Seam layer).
>>
>> However with mybatis-guice the type handler only works for writing to the
>> DB. On reading I only ever get null’s.
>>
>>
>>
>> I have tried to debug the problem, and it seems to me that mappers are
>> registered/built before type handlers,
>>
>> so the ResultMapping that is used when reading the property has a null
>> typeHandler.
>>
>>
>>
>> As a fix I changed ConfigurationProvider: After moving the lines containing
>> the method registerTypeHandler
>>
>> in front of the registerMappers method it starts to work.
>>
>>
>>
>> However I am not sure if that relies on an implementation detail of Guice:
>> Is the order of calls to @Inject
>>
>> methods specified?
>>
>>
>>
>> -- Stephen
>>
>>
>

configuration-provider.patch (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
Hi Stephen,
thanks a lot to you for the deep review, I just applied your patch,
with trivial modifications, see the comment on the issue tracker.
I don't think we should need a finally block since the configuration
object just collects aliases, handlers, etc etc and shouldn't trow an
error at all.
I'll release the RC2 with your modifications today, stay tuned! :)
Alles gute,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
<[hidden email]> wrote:

> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
> On second thought the call to ErrorContext.release() should better be in a finally block, right?
> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>
> -- Stephen
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Mittwoch, 15. September 2010 09:19
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> You rock Stephen,
> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
> Alles gute!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
> <[hidden email]> wrote:
>> Hi Simo,
>>
>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>
>> -- Stephen
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Sonntag, 12. September 2010 21:10
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> Hi Stephen,
>> good catch!!! Unfortunately Guice doesn't have an option to specify
>> the @Inject order, and AFAIK relies on methods order declaration.
>> If you would like to provide a patch I'd be more than pleased to apply
>> it and release soon an RC2 with this fix.
>> Thanks in advance, have a nice day,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>> class.
>>>
>>> That type handler works fine in an application using “pure” mybatis (with my
>>> own very thin Seam layer).
>>>
>>> However with mybatis-guice the type handler only works for writing to the
>>> DB. On reading I only ever get null’s.
>>>
>>>
>>>
>>> I have tried to debug the problem, and it seems to me that mappers are
>>> registered/built before type handlers,
>>>
>>> so the ResultMapping that is used when reading the property has a null
>>> typeHandler.
>>>
>>>
>>>
>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>> the method registerTypeHandler
>>>
>>> in front of the registerMappers method it starts to work.
>>>
>>>
>>>
>>> However I am not sure if that relies on an implementation detail of Guice:
>>> Is the order of calls to @Inject
>>>
>>> methods specified?
>>>
>>>
>>>
>>> -- Stephen
>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

AW: mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich
Sorry to argue the point, but I think the finally-block is important:
I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
In that case the ErrorContext never gets released:

Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)

Sure enough on undeployment Tomcat complains about the leak:
        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type [org.apache.ibatis.executor.ErrorContext] (value [
        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

-- Stephen

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
Gesendet: Mittwoch, 15. September 2010 10:25
An: [hidden email]
Betreff: Re: mybatis-guice: custom TypeHandler works only halfway

Hi Stephen,
thanks a lot to you for the deep review, I just applied your patch,
with trivial modifications, see the comment on the issue tracker.
I don't think we should need a finally block since the configuration
object just collects aliases, handlers, etc etc and shouldn't trow an
error at all.
I'll release the RC2 with your modifications today, stay tuned! :)
Alles gute,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
<[hidden email]> wrote:

> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
> On second thought the call to ErrorContext.release() should better be in a finally block, right?
> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>
> -- Stephen
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Mittwoch, 15. September 2010 09:19
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> You rock Stephen,
> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
> Alles gute!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
> <[hidden email]> wrote:
>> Hi Simo,
>>
>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>
>> -- Stephen
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Sonntag, 12. September 2010 21:10
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> Hi Stephen,
>> good catch!!! Unfortunately Guice doesn't have an option to specify
>> the @Inject order, and AFAIK relies on methods order declaration.
>> If you would like to provide a patch I'd be more than pleased to apply
>> it and release soon an RC2 with this fix.
>> Thanks in advance, have a nice day,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>> class.
>>>
>>> That type handler works fine in an application using “pure” mybatis (with my
>>> own very thin Seam layer).
>>>
>>> However with mybatis-guice the type handler only works for writing to the
>>> DB. On reading I only ever get null’s.
>>>
>>>
>>>
>>> I have tried to debug the problem, and it seems to me that mappers are
>>> registered/built before type handlers,
>>>
>>> so the ResultMapping that is used when reading the property has a null
>>> typeHandler.
>>>
>>>
>>>
>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>> the method registerTypeHandler
>>>
>>> in front of the registerMappers method it starts to work.
>>>
>>>
>>>
>>> However I am not sure if that relies on an implementation detail of Guice:
>>> Is the order of calls to @Inject
>>>
>>> methods specified?
>>>
>>>
>>>
>>> -- Stephen
>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
It makes a lot of sense, I'm going to apply this modification.
Good catch!
Simo

PS Off topic: that's the first time I see a localized log4j log,
SCHWERWIEGEND sounds error/warning :P

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
<[hidden email]> wrote:

> Sorry to argue the point, but I think the finally-block is important:
> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
> In that case the ErrorContext never gets released:
>
> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>
> Sure enough on undeployment Tomcat complains about the leak:
>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>
> -- Stephen
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Mittwoch, 15. September 2010 10:25
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> Hi Stephen,
> thanks a lot to you for the deep review, I just applied your patch,
> with trivial modifications, see the comment on the issue tracker.
> I don't think we should need a finally block since the configuration
> object just collects aliases, handlers, etc etc and shouldn't trow an
> error at all.
> I'll release the RC2 with your modifications today, stay tuned! :)
> Alles gute,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
> <[hidden email]> wrote:
>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>
>> -- Stephen
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Mittwoch, 15. September 2010 09:19
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> You rock Stephen,
>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>> Alles gute!
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> Hi Simo,
>>>
>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>
>>> -- Stephen
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>> Gesendet: Sonntag, 12. September 2010 21:10
>>> An: [hidden email]
>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>
>>> Hi Stephen,
>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>> the @Inject order, and AFAIK relies on methods order declaration.
>>> If you would like to provide a patch I'd be more than pleased to apply
>>> it and release soon an RC2 with this fix.
>>> Thanks in advance, have a nice day,
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>> class.
>>>>
>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>> own very thin Seam layer).
>>>>
>>>> However with mybatis-guice the type handler only works for writing to the
>>>> DB. On reading I only ever get null’s.
>>>>
>>>>
>>>>
>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>> registered/built before type handlers,
>>>>
>>>> so the ResultMapping that is used when reading the property has a null
>>>> typeHandler.
>>>>
>>>>
>>>>
>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>> the method registerTypeHandler
>>>>
>>>> in front of the registerMappers method it starts to work.
>>>>
>>>>
>>>>
>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>> Is the order of calls to @Inject
>>>>
>>>> methods specified?
>>>>
>>>>
>>>>
>>>> -- Stephen
>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
Done, see the ConfigurationProvider r2446.
WDYT, at that stage, can I proceed on releasing the RC2?
Thanks a lot for your collaboration!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 10:56 AM, Simone Tripodi
<[hidden email]> wrote:

> It makes a lot of sense, I'm going to apply this modification.
> Good catch!
> Simo
>
> PS Off topic: that's the first time I see a localized log4j log,
> SCHWERWIEGEND sounds error/warning :P
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
> <[hidden email]> wrote:
>> Sorry to argue the point, but I think the finally-block is important:
>> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
>> In that case the ErrorContext never gets released:
>>
>> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>>
>> Sure enough on undeployment Tomcat complains about the leak:
>>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>
>> -- Stephen
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Mittwoch, 15. September 2010 10:25
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> Hi Stephen,
>> thanks a lot to you for the deep review, I just applied your patch,
>> with trivial modifications, see the comment on the issue tracker.
>> I don't think we should need a finally block since the configuration
>> object just collects aliases, handlers, etc etc and shouldn't trow an
>> error at all.
>> I'll release the RC2 with your modifications today, stay tuned! :)
>> Alles gute,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>>
>>> -- Stephen
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>> Gesendet: Mittwoch, 15. September 2010 09:19
>>> An: [hidden email]
>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>
>>> You rock Stephen,
>>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>>> Alles gute!
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> Hi Simo,
>>>>
>>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>>
>>>> -- Stephen
>>>>
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>> Gesendet: Sonntag, 12. September 2010 21:10
>>>> An: [hidden email]
>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>
>>>> Hi Stephen,
>>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>>> the @Inject order, and AFAIK relies on methods order declaration.
>>>> If you would like to provide a patch I'd be more than pleased to apply
>>>> it and release soon an RC2 with this fix.
>>>> Thanks in advance, have a nice day,
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>>> <[hidden email]> wrote:
>>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>>> class.
>>>>>
>>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>>> own very thin Seam layer).
>>>>>
>>>>> However with mybatis-guice the type handler only works for writing to the
>>>>> DB. On reading I only ever get null’s.
>>>>>
>>>>>
>>>>>
>>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>>> registered/built before type handlers,
>>>>>
>>>>> so the ResultMapping that is used when reading the property has a null
>>>>> typeHandler.
>>>>>
>>>>>
>>>>>
>>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>>> the method registerTypeHandler
>>>>>
>>>>> in front of the registerMappers method it starts to work.
>>>>>
>>>>>
>>>>>
>>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>>> Is the order of calls to @Inject
>>>>>
>>>>> methods specified?
>>>>>
>>>>>
>>>>>
>>>>> -- Stephen
>>>>>
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

AW: mybatis-guice: custom TypeHandler works only halfway

Stephen Friedrich
Thanks again! I build a fresh jar from latest svn and ran my app tests with that.
Looks fine. No test failures, no memory leaks.

-- Stephen

BTW: SCHWERWIEGEND is log4j's translation for FATAL
Which reminds me that I want to move to logback...

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
Gesendet: Mittwoch, 15. September 2010 11:01
An: [hidden email]
Betreff: Re: mybatis-guice: custom TypeHandler works only halfway

Done, see the ConfigurationProvider r2446.
WDYT, at that stage, can I proceed on releasing the RC2?
Thanks a lot for your collaboration!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 10:56 AM, Simone Tripodi
<[hidden email]> wrote:

> It makes a lot of sense, I'm going to apply this modification.
> Good catch!
> Simo
>
> PS Off topic: that's the first time I see a localized log4j log,
> SCHWERWIEGEND sounds error/warning :P
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
> <[hidden email]> wrote:
>> Sorry to argue the point, but I think the finally-block is important:
>> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
>> In that case the ErrorContext never gets released:
>>
>> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>>
>> Sure enough on undeployment Tomcat complains about the leak:
>>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>
>> -- Stephen
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Mittwoch, 15. September 2010 10:25
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> Hi Stephen,
>> thanks a lot to you for the deep review, I just applied your patch,
>> with trivial modifications, see the comment on the issue tracker.
>> I don't think we should need a finally block since the configuration
>> object just collects aliases, handlers, etc etc and shouldn't trow an
>> error at all.
>> I'll release the RC2 with your modifications today, stay tuned! :)
>> Alles gute,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>>
>>> -- Stephen
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>> Gesendet: Mittwoch, 15. September 2010 09:19
>>> An: [hidden email]
>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>
>>> You rock Stephen,
>>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>>> Alles gute!
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> Hi Simo,
>>>>
>>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>>
>>>> -- Stephen
>>>>
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>> Gesendet: Sonntag, 12. September 2010 21:10
>>>> An: [hidden email]
>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>
>>>> Hi Stephen,
>>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>>> the @Inject order, and AFAIK relies on methods order declaration.
>>>> If you would like to provide a patch I'd be more than pleased to apply
>>>> it and release soon an RC2 with this fix.
>>>> Thanks in advance, have a nice day,
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>>> <[hidden email]> wrote:
>>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>>> class.
>>>>>
>>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>>> own very thin Seam layer).
>>>>>
>>>>> However with mybatis-guice the type handler only works for writing to the
>>>>> DB. On reading I only ever get null’s.
>>>>>
>>>>>
>>>>>
>>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>>> registered/built before type handlers,
>>>>>
>>>>> so the ResultMapping that is used when reading the property has a null
>>>>> typeHandler.
>>>>>
>>>>>
>>>>>
>>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>>> the method registerTypeHandler
>>>>>
>>>>> in front of the registerMappers method it starts to work.
>>>>>
>>>>>
>>>>>
>>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>>> Is the order of calls to @Inject
>>>>>
>>>>> methods specified?
>>>>>
>>>>>
>>>>>
>>>>> -- Stephen
>>>>>
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
Excellent, going to release it NOW :)
thanks to you for the great help!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 12:07 PM, Stephen Friedrich
<[hidden email]> wrote:

> Thanks again! I build a fresh jar from latest svn and ran my app tests with that.
> Looks fine. No test failures, no memory leaks.
>
> -- Stephen
>
> BTW: SCHWERWIEGEND is log4j's translation for FATAL
> Which reminds me that I want to move to logback...
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Mittwoch, 15. September 2010 11:01
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> Done, see the ConfigurationProvider r2446.
> WDYT, at that stage, can I proceed on releasing the RC2?
> Thanks a lot for your collaboration!!!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 10:56 AM, Simone Tripodi
> <[hidden email]> wrote:
>> It makes a lot of sense, I'm going to apply this modification.
>> Good catch!
>> Simo
>>
>> PS Off topic: that's the first time I see a localized log4j log,
>> SCHWERWIEGEND sounds error/warning :P
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> Sorry to argue the point, but I think the finally-block is important:
>>> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
>>> In that case the ErrorContext never gets released:
>>>
>>> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>>>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>>>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>>>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>>>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>>>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>>>
>>> Sure enough on undeployment Tomcat complains about the leak:
>>>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>>>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>>>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>>
>>> -- Stephen
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>> Gesendet: Mittwoch, 15. September 2010 10:25
>>> An: [hidden email]
>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>
>>> Hi Stephen,
>>> thanks a lot to you for the deep review, I just applied your patch,
>>> with trivial modifications, see the comment on the issue tracker.
>>> I don't think we should need a finally block since the configuration
>>> object just collects aliases, handlers, etc etc and shouldn't trow an
>>> error at all.
>>> I'll release the RC2 with your modifications today, stay tuned! :)
>>> Alles gute,
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>>>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>>>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>>>
>>>> -- Stephen
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>> Gesendet: Mittwoch, 15. September 2010 09:19
>>>> An: [hidden email]
>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>
>>>> You rock Stephen,
>>>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>>>> Alles gute!
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>>>> <[hidden email]> wrote:
>>>>> Hi Simo,
>>>>>
>>>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>>>
>>>>> -- Stephen
>>>>>
>>>>>
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>>> Gesendet: Sonntag, 12. September 2010 21:10
>>>>> An: [hidden email]
>>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>>
>>>>> Hi Stephen,
>>>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>>>> the @Inject order, and AFAIK relies on methods order declaration.
>>>>> If you would like to provide a patch I'd be more than pleased to apply
>>>>> it and release soon an RC2 with this fix.
>>>>> Thanks in advance, have a nice day,
>>>>> Simo
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>>>> <[hidden email]> wrote:
>>>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>>>> class.
>>>>>>
>>>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>>>> own very thin Seam layer).
>>>>>>
>>>>>> However with mybatis-guice the type handler only works for writing to the
>>>>>> DB. On reading I only ever get null’s.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>>>> registered/built before type handlers,
>>>>>>
>>>>>> so the ResultMapping that is used when reading the property has a null
>>>>>> typeHandler.
>>>>>>
>>>>>>
>>>>>>
>>>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>>>> the method registerTypeHandler
>>>>>>
>>>>>> in front of the registerMappers method it starts to work.
>>>>>>
>>>>>>
>>>>>>
>>>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>>>> Is the order of calls to @Inject
>>>>>>
>>>>>> methods specified?
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- Stephen
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

RE: mybatis-guice: custom TypeHandler works only halfway

Poitras Christian
As a site note, Guice itself has a memory leak. I've noted this on my tomcat installation.

See http://code.google.com/p/google-guice/issues/detail?id=288

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Simone Tripodi
Envoyé : September-15-10 6:15 AM
À : [hidden email]
Objet : Re: mybatis-guice: custom TypeHandler works only halfway

Excellent, going to release it NOW :)
thanks to you for the great help!!!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 12:07 PM, Stephen Friedrich
<[hidden email]> wrote:

> Thanks again! I build a fresh jar from latest svn and ran my app tests with that.
> Looks fine. No test failures, no memory leaks.
>
> -- Stephen
>
> BTW: SCHWERWIEGEND is log4j's translation for FATAL
> Which reminds me that I want to move to logback...
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
> Gesendet: Mittwoch, 15. September 2010 11:01
> An: [hidden email]
> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>
> Done, see the ConfigurationProvider r2446.
> WDYT, at that stage, can I proceed on releasing the RC2?
> Thanks a lot for your collaboration!!!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 10:56 AM, Simone Tripodi
> <[hidden email]> wrote:
>> It makes a lot of sense, I'm going to apply this modification.
>> Good catch!
>> Simo
>>
>> PS Off topic: that's the first time I see a localized log4j log,
>> SCHWERWIEGEND sounds error/warning :P
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
>> <[hidden email]> wrote:
>>> Sorry to argue the point, but I think the finally-block is important:
>>> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
>>> In that case the ErrorContext never gets released:
>>>
>>> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>>>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>>>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>>>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>>>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>>>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>>>
>>> Sure enough on undeployment Tomcat complains about the leak:
>>>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>>>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>>>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>>
>>> -- Stephen
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>> Gesendet: Mittwoch, 15. September 2010 10:25
>>> An: [hidden email]
>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>
>>> Hi Stephen,
>>> thanks a lot to you for the deep review, I just applied your patch,
>>> with trivial modifications, see the comment on the issue tracker.
>>> I don't think we should need a finally block since the configuration
>>> object just collects aliases, handlers, etc etc and shouldn't trow an
>>> error at all.
>>> I'll release the RC2 with your modifications today, stay tuned! :)
>>> Alles gute,
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>>>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>>>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>>>
>>>> -- Stephen
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>> Gesendet: Mittwoch, 15. September 2010 09:19
>>>> An: [hidden email]
>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>
>>>> You rock Stephen,
>>>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>>>> Alles gute!
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>>>> <[hidden email]> wrote:
>>>>> Hi Simo,
>>>>>
>>>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>>>
>>>>> -- Stephen
>>>>>
>>>>>
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>>> Gesendet: Sonntag, 12. September 2010 21:10
>>>>> An: [hidden email]
>>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>>
>>>>> Hi Stephen,
>>>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>>>> the @Inject order, and AFAIK relies on methods order declaration.
>>>>> If you would like to provide a patch I'd be more than pleased to apply
>>>>> it and release soon an RC2 with this fix.
>>>>> Thanks in advance, have a nice day,
>>>>> Simo
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>>>> <[hidden email]> wrote:
>>>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>>>> class.
>>>>>>
>>>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>>>> own very thin Seam layer).
>>>>>>
>>>>>> However with mybatis-guice the type handler only works for writing to the
>>>>>> DB. On reading I only ever get null’s.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>>>> registered/built before type handlers,
>>>>>>
>>>>>> so the ResultMapping that is used when reading the property has a null
>>>>>> typeHandler.
>>>>>>
>>>>>>
>>>>>>
>>>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>>>> the method registerTypeHandler
>>>>>>
>>>>>> in front of the registerMappers method it starts to work.
>>>>>>
>>>>>>
>>>>>>
>>>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>>>> Is the order of calls to @Inject
>>>>>>
>>>>>> methods specified?
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- Stephen
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice: custom TypeHandler works only halfway

Simone Tripodi
Thanks for notifying it, nice to know it!!! :)
all the best,
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 2:59 PM, Poitras Christian
<[hidden email]> wrote:

> As a site note, Guice itself has a memory leak. I've noted this on my tomcat installation.
>
> See http://code.google.com/p/google-guice/issues/detail?id=288
>
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Simone Tripodi
> Envoyé : September-15-10 6:15 AM
> À : [hidden email]
> Objet : Re: mybatis-guice: custom TypeHandler works only halfway
>
> Excellent, going to release it NOW :)
> thanks to you for the great help!!!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 12:07 PM, Stephen Friedrich
> <[hidden email]> wrote:
>> Thanks again! I build a fresh jar from latest svn and ran my app tests with that.
>> Looks fine. No test failures, no memory leaks.
>>
>> -- Stephen
>>
>> BTW: SCHWERWIEGEND is log4j's translation for FATAL
>> Which reminds me that I want to move to logback...
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>> Gesendet: Mittwoch, 15. September 2010 11:01
>> An: [hidden email]
>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>
>> Done, see the ConfigurationProvider r2446.
>> WDYT, at that stage, can I proceed on releasing the RC2?
>> Thanks a lot for your collaboration!!!
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 10:56 AM, Simone Tripodi
>> <[hidden email]> wrote:
>>> It makes a lot of sense, I'm going to apply this modification.
>>> Good catch!
>>> Simo
>>>
>>> PS Off topic: that's the first time I see a localized log4j log,
>>> SCHWERWIEGEND sounds error/warning :P
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Sep 15, 2010 at 10:46 AM, Stephen Friedrich
>>> <[hidden email]> wrote:
>>>> Sorry to argue the point, but I think the finally-block is important:
>>>> I just checked the behaviour with a syntax error in one of the mapping xml files - I think that's a common situation.
>>>> In that case the ErrorContext never gets released:
>>>>
>>>> Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
>>>>        at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:212)
>>>>        at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:81)
>>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:31)
>>>>        at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:24)
>>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:70)
>>>>        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:49)
>>>>        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:43)
>>>>        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:371)
>>>>        at org.mybatis.guice.configuration.ConfigurationProvider.postCreate(ConfigurationProvider.java:77)
>>>>
>>>> Sure enough on undeployment Tomcat complains about the leak:
>>>>        15.09.2010 10:43:17 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
>>>>        SCHWERWIEGEND: The web application [/weblog] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@11c3288]) and a value of type         [org.apache.ibatis.executor.ErrorContext] (value [
>>>>        ### The error may exist in de/fortis/weblog/mappers/TaskMapper.xml]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
>>>>
>>>> -- Stephen
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>> Gesendet: Mittwoch, 15. September 2010 10:25
>>>> An: [hidden email]
>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>
>>>> Hi Stephen,
>>>> thanks a lot to you for the deep review, I just applied your patch,
>>>> with trivial modifications, see the comment on the issue tracker.
>>>> I don't think we should need a finally block since the configuration
>>>> object just collects aliases, handlers, etc etc and shouldn't trow an
>>>> error at all.
>>>> I'll release the RC2 with your modifications today, stay tuned! :)
>>>> Alles gute,
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Wed, Sep 15, 2010 at 10:18 AM, Stephen Friedrich
>>>> <[hidden email]> wrote:
>>>>> Thanks! Looking forward to remove my local patch from my app and switch back to the official version.
>>>>> On second thought the call to ErrorContext.release() should better be in a finally block, right?
>>>>> (Just in case an exception occurs during configuration after the ErrorContext has already been created).
>>>>>
>>>>> -- Stephen
>>>>>
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>>> Gesendet: Mittwoch, 15. September 2010 09:19
>>>>> An: [hidden email]
>>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>>
>>>>> You rock Stephen,
>>>>> thanks for the patch, you'll be mentioned as mybatis-guice contributor :)
>>>>> Alles gute!
>>>>> Simo
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Sep 15, 2010 at 2:22 AM, Stephen Friedrich
>>>>> <[hidden email]> wrote:
>>>>>> Hi Simo,
>>>>>>
>>>>>> finally here's a patch for the ordering problem and for the memory leak due to ErrorContext.
>>>>>>
>>>>>> -- Stephen
>>>>>>
>>>>>>
>>>>>> -----Ursprüngliche Nachricht-----
>>>>>> Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Simone Tripodi
>>>>>> Gesendet: Sonntag, 12. September 2010 21:10
>>>>>> An: [hidden email]
>>>>>> Betreff: Re: mybatis-guice: custom TypeHandler works only halfway
>>>>>>
>>>>>> Hi Stephen,
>>>>>> good catch!!! Unfortunately Guice doesn't have an option to specify
>>>>>> the @Inject order, and AFAIK relies on methods order declaration.
>>>>>> If you would like to provide a patch I'd be more than pleased to apply
>>>>>> it and release soon an RC2 with this fix.
>>>>>> Thanks in advance, have a nice day,
>>>>>> Simo
>>>>>>
>>>>>> http://people.apache.org/~simonetripodi/
>>>>>> http://www.99soft.org/
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sun, Sep 12, 2010 at 8:14 PM, Stephen Friedrich
>>>>>> <[hidden email]> wrote:
>>>>>>> I am using a custom TypeHandler for conversion to/from Joda Time LocalDate
>>>>>>> class.
>>>>>>>
>>>>>>> That type handler works fine in an application using “pure” mybatis (with my
>>>>>>> own very thin Seam layer).
>>>>>>>
>>>>>>> However with mybatis-guice the type handler only works for writing to the
>>>>>>> DB. On reading I only ever get null’s.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I have tried to debug the problem, and it seems to me that mappers are
>>>>>>> registered/built before type handlers,
>>>>>>>
>>>>>>> so the ResultMapping that is used when reading the property has a null
>>>>>>> typeHandler.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> As a fix I changed ConfigurationProvider: After moving the lines containing
>>>>>>> the method registerTypeHandler
>>>>>>>
>>>>>>> in front of the registerMappers method it starts to work.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> However I am not sure if that relies on an implementation detail of Guice:
>>>>>>> Is the order of calls to @Inject
>>>>>>>
>>>>>>> methods specified?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> -- Stephen
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

mybatis-guice with XML

Poitras Christian
In reply to this post by Poitras Christian
Hi Simo,

I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.

Beside that it's a simple matter of binding a SqlSessionManager instance.
// Bind SqlSessionManager.
bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
// Bind mappers.
bindMapper(this.binder(), ReferenceMapper.class);

Even the @Transactional tag woks!
// Bind MyBatis-Guice interceptor for @Transactional.
TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
this.binder().requestInjection(interceptor);
this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);


As a site note, is it possible to use @Transactional tag with multiple datasource?
I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.

Christian
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice with XML

Simone Tripodi
Hi mate! :)
Yes sure, I can do a little more (I need 5 minutes to implement it but
more time to release it since I've to write the doc):
 * re-enabling the XML SqlSessionManagerProvider (that was already
present in iBaGuice) and give you a method in the Module to plug your
preferred Provider (with a default one)
* exposing the the method to bind the mappers, so you don't have to
write the boilerplate code.

About @Transactional in multiple datasource... honestly I'd say it
depends which private module builds the class where methods are marked
with @Transactional!!! I need to do a more deeeeeeeeeeply try to
better reply you.

Let's keep in touch, I'll let you know ASAP
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 3:17 PM, Poitras Christian
<[hidden email]> wrote:

> Hi Simo,
>
> I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
> is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.
>
> Beside that it's a simple matter of binding a SqlSessionManager instance.
> // Bind SqlSessionManager.
> bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
> bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
> bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
> // Bind mappers.
> bindMapper(this.binder(), ReferenceMapper.class);
>
> Even the @Transactional tag woks!
> // Bind MyBatis-Guice interceptor for @Transactional.
> TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
> this.binder().requestInjection(interceptor);
> this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
>
>
> As a site note, is it possible to use @Transactional tag with multiple datasource?
> I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
> But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
> This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.
>
> Christian
>
Reply | Threaded
Open this post in threaded view
|

RE: mybatis-guice with XML

Poitras Christian
I'll explain a little more what I would like to do.

Let's say I have a module with the following code:
public static class DummyModule extends AbstractModule {
    @Override
    protected void configure() { install(new PrivateModule(){
        @Override
        protected void configure() {
            TransactionalInterceptor interceptor = new TransactionalInterceptor ();
            requestInjection(interceptor);
            bindInterceptor(Matchers.any(), Matchers.any(), interceptor);
        }
    });

    // Intercept methods of Dummy with TransactionalInterceptor.
    bind(Dummy.class);
}

I would like TransactionalInterceptor to intercept calls to Dummy. But since the TransactionalInterceptor's binding is declared in a private module, Dummy's method will not be intercepted.

I know I can bind Dummy inside the PrivateModule and expose it afterwards. But if I do this in my program, I would be forced to put almost all my classes inside the same Private module which I find undesirable.
One option would be to move the TransactionalInterceptor outside the PrivateModule, but doing this will not allow me bind different instances of SqlSessionManager...

I'm trying to find information about the use of Interceptors and PrivateModule, but I haven't found anything interesting yet.

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Simone Tripodi
Envoyé : September-15-10 9:37 AM
À : [hidden email]
Objet : Re: mybatis-guice with XML

Hi mate! :)
Yes sure, I can do a little more (I need 5 minutes to implement it but
more time to release it since I've to write the doc):
 * re-enabling the XML SqlSessionManagerProvider (that was already
present in iBaGuice) and give you a method in the Module to plug your
preferred Provider (with a default one)
* exposing the the method to bind the mappers, so you don't have to
write the boilerplate code.

About @Transactional in multiple datasource... honestly I'd say it
depends which private module builds the class where methods are marked
with @Transactional!!! I need to do a more deeeeeeeeeeply try to
better reply you.

Let's keep in touch, I'll let you know ASAP
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 3:17 PM, Poitras Christian
<[hidden email]> wrote:

> Hi Simo,
>
> I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
> is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.
>
> Beside that it's a simple matter of binding a SqlSessionManager instance.
> // Bind SqlSessionManager.
> bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
> bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
> bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
> // Bind mappers.
> bindMapper(this.binder(), ReferenceMapper.class);
>
> Even the @Transactional tag woks!
> // Bind MyBatis-Guice interceptor for @Transactional.
> TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
> this.binder().requestInjection(interceptor);
> this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
>
>
> As a site note, is it possible to use @Transactional tag with multiple datasource?
> I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
> But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
> This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.
>
> Christian
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice with XML

Simone Tripodi
In reply to this post by Simone Tripodi
Done :)
please check out the current /trunk development to use that new
feature (it needs to be tested and that would be the nice time).

You can now use the XMLMyBatisModule in that way:

Guice.createInjector(
                    new XMLMyBatisModule()
                        .addMapperClasses(MyFooMapper.class, MyBarMapper.class),
                    new Module() {
                        public void configure(Binder binder) {

binder.bindConstant().annotatedWith(Names.named("mybatis.classpathResource")).to("com/acme/contacts-sqlmapper.xml");
                        }
                    })

Of course, if you have suggestions to improve APIs, you're more than welcome :)
Break a leg!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 3:36 PM, Simone Tripodi
<[hidden email]> wrote:

> Hi mate! :)
> Yes sure, I can do a little more (I need 5 minutes to implement it but
> more time to release it since I've to write the doc):
>  * re-enabling the XML SqlSessionManagerProvider (that was already
> present in iBaGuice) and give you a method in the Module to plug your
> preferred Provider (with a default one)
> * exposing the the method to bind the mappers, so you don't have to
> write the boilerplate code.
>
> About @Transactional in multiple datasource... honestly I'd say it
> depends which private module builds the class where methods are marked
> with @Transactional!!! I need to do a more deeeeeeeeeeply try to
> better reply you.
>
> Let's keep in touch, I'll let you know ASAP
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 3:17 PM, Poitras Christian
> <[hidden email]> wrote:
>> Hi Simo,
>>
>> I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
>> is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.
>>
>> Beside that it's a simple matter of binding a SqlSessionManager instance.
>> // Bind SqlSessionManager.
>> bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
>> bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
>> bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
>> // Bind mappers.
>> bindMapper(this.binder(), ReferenceMapper.class);
>>
>> Even the @Transactional tag woks!
>> // Bind MyBatis-Guice interceptor for @Transactional.
>> TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
>> this.binder().requestInjection(interceptor);
>> this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
>>
>>
>> As a site note, is it possible to use @Transactional tag with multiple datasource?
>> I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
>> But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
>> This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.
>>
>> Christian
>>
>
Reply | Threaded
Open this post in threaded view
|

RE: mybatis-guice with XML

Poitras Christian
Looks simple enough! I'll try it!

Thanks!
Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de Simone Tripodi
Envoyé : September-15-10 10:09 AM
À : [hidden email]
Objet : Re: mybatis-guice with XML

Done :)
please check out the current /trunk development to use that new
feature (it needs to be tested and that would be the nice time).

You can now use the XMLMyBatisModule in that way:

Guice.createInjector(
                    new XMLMyBatisModule()
                        .addMapperClasses(MyFooMapper.class, MyBarMapper.class),
                    new Module() {
                        public void configure(Binder binder) {

binder.bindConstant().annotatedWith(Names.named("mybatis.classpathResource")).to("com/acme/contacts-sqlmapper.xml");
                        }
                    })

Of course, if you have suggestions to improve APIs, you're more than welcome :)
Break a leg!
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 3:36 PM, Simone Tripodi
<[hidden email]> wrote:

> Hi mate! :)
> Yes sure, I can do a little more (I need 5 minutes to implement it but
> more time to release it since I've to write the doc):
>  * re-enabling the XML SqlSessionManagerProvider (that was already
> present in iBaGuice) and give you a method in the Module to plug your
> preferred Provider (with a default one)
> * exposing the the method to bind the mappers, so you don't have to
> write the boilerplate code.
>
> About @Transactional in multiple datasource... honestly I'd say it
> depends which private module builds the class where methods are marked
> with @Transactional!!! I need to do a more deeeeeeeeeeply try to
> better reply you.
>
> Let's keep in touch, I'll let you know ASAP
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 3:17 PM, Poitras Christian
> <[hidden email]> wrote:
>> Hi Simo,
>>
>> I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
>> is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.
>>
>> Beside that it's a simple matter of binding a SqlSessionManager instance.
>> // Bind SqlSessionManager.
>> bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
>> bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
>> bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
>> // Bind mappers.
>> bindMapper(this.binder(), ReferenceMapper.class);
>>
>> Even the @Transactional tag woks!
>> // Bind MyBatis-Guice interceptor for @Transactional.
>> TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
>> this.binder().requestInjection(interceptor);
>> this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
>>
>>
>> As a site note, is it possible to use @Transactional tag with multiple datasource?
>> I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
>> But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
>> This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.
>>
>> Christian
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: mybatis-guice with XML

Simone Tripodi
Please let me know! :)
In the meanwhile I'll study the problem you submitted, let see what we
can do... :P
Simo

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Wed, Sep 15, 2010 at 4:10 PM, Poitras Christian
<[hidden email]> wrote:

> Looks simple enough! I'll try it!
>
> Thanks!
> Christian
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De la part de Simone Tripodi
> Envoyé : September-15-10 10:09 AM
> À : [hidden email]
> Objet : Re: mybatis-guice with XML
>
> Done :)
> please check out the current /trunk development to use that new
> feature (it needs to be tested and that would be the nice time).
>
> You can now use the XMLMyBatisModule in that way:
>
> Guice.createInjector(
>                    new XMLMyBatisModule()
>                        .addMapperClasses(MyFooMapper.class, MyBarMapper.class),
>                    new Module() {
>                        public void configure(Binder binder) {
>
> binder.bindConstant().annotatedWith(Names.named("mybatis.classpathResource")).to("com/acme/contacts-sqlmapper.xml");
>                        }
>                    })
>
> Of course, if you have suggestions to improve APIs, you're more than welcome :)
> Break a leg!
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Sep 15, 2010 at 3:36 PM, Simone Tripodi
> <[hidden email]> wrote:
>> Hi mate! :)
>> Yes sure, I can do a little more (I need 5 minutes to implement it but
>> more time to release it since I've to write the doc):
>>  * re-enabling the XML SqlSessionManagerProvider (that was already
>> present in iBaGuice) and give you a method in the Module to plug your
>> preferred Provider (with a default one)
>> * exposing the the method to bind the mappers, so you don't have to
>> write the boilerplate code.
>>
>> About @Transactional in multiple datasource... honestly I'd say it
>> depends which private module builds the class where methods are marked
>> with @Transactional!!! I need to do a more deeeeeeeeeeply try to
>> better reply you.
>>
>> Let's keep in touch, I'll let you know ASAP
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Sep 15, 2010 at 3:17 PM, Poitras Christian
>> <[hidden email]> wrote:
>>> Hi Simo,
>>>
>>> I've tried using MyBatis-Guice with some XML configuration and I've faced an issue:
>>> is it possible to make MapperProvider and SqlSessionManagerProvider classes public? I've just copied the classes in my workspace and made them public to be able to use them.
>>>
>>> Beside that it's a simple matter of binding a SqlSessionManager instance.
>>> // Bind SqlSessionManager.
>>> bind(TransactionFactory.class).toProvider(JdbcTransactionFactoryProvider.class).in(Scopes.SINGLETON);
>>> bind(SqlSessionFactory.class).toProvider(SqlSessionFactoryProvider.class).in(Scopes.SINGLETON); // custom provider that loads my XML file - not in MyBatis-Guice.
>>> bind(SqlSessionManager.class).toProvider(SqlSessionManagerProvider.class).in(Scopes.SINGLETON);
>>> // Bind mappers.
>>> bindMapper(this.binder(), ReferenceMapper.class);
>>>
>>> Even the @Transactional tag woks!
>>> // Bind MyBatis-Guice interceptor for @Transactional.
>>> TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
>>> this.binder().requestInjection(interceptor);
>>> this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Transactional.class), interceptor);
>>>
>>>
>>> As a site note, is it possible to use @Transactional tag with multiple datasource?
>>> I've seen the post here http://groups.google.com/group/ibaguice/browse_thread/thread/5cb4e3e9c0c70e4e
>>> But I need to inject instance for the interceptor inside a PrivateModule to inject the right instance of SqlSessionManager. But when I do this, the interceptor intercepts only calls to objects that are bind inside the PrivateModule which is undesirable. I would like the interceptor to intercept calls to all any classes having the @Transactional class.
>>> This is more a Guice question than a MyBatis-Guice question, but I thought you might already have the solution.
>>>
>>> Christian
>>>
>>
>
1234