RE: Mybatis-guice, configuring default exception type for @Transactional

104 views
Skip to first unread message

Poitras Christian

unread,
Jul 19, 2012, 10:48:18 AM7/19/12
to mybati...@googlegroups.com

Hi,

 

In such a case, it may be better to add an your own rethrow interceptor over @Transactional.

That way, you don’t have to modify every @Transactional annotations and it’s easier to maintain.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Stephane C.
Envoyé : July-19-12 5:14 AM
À : mybati...@googlegroups.com
Objet : Mybatis-guice, configuring default exception type for @Transactional

 

Hello,

 

I really appreciate the @Transactional annotation provided by mybatis-guice (and by the way, thanks Simone for maintaining it over years).

 

@Transactional(
        executorType = ExecutorType.BATCH,
        isolation = Isolation.READ_UNCOMMITTED,
        rethrowExceptionsAs = MyDaoException.class,

However, I would like my service layer to use my own data access exception class all the time so it would be great if I could define a default value for rethrowExceptionAs in a single place instead of specifying it above every method.

Looking at the source code, it does not seem possible at the moment but maybe it's worth considering in a future release?

 

Best

 

Poitras Christian

unread,
Jul 19, 2012, 10:50:39 AM7/19/12
to mybati...@googlegroups.com

Sorry, I didn’t read your question correctly.

 

But my point is still valid. By using a custom interceptor you can handle the exception the way you like and MyBatis-Guice interceptor will still work its magic.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Poitras Christian
Envoyé : July-19-12 10:48 AM
À : 'mybati...@googlegroups.com'
Objet : RE: Mybatis-guice, configuring default exception type for @Transactional

Simone Tripodi

unread,
Jul 21, 2012, 4:02:00 PM7/21/12
to mybati...@googlegroups.com
Hi Stephane,

> Looking at the source code, it does not seem possible at the moment but
> maybe it's worth considering in a future release?

I think it could be possible - can you feel me an issue as a reminder, please?
TIA!
-Simo

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

Stephane C.

unread,
Jul 25, 2012, 3:22:51 AM7/25/12
to mybati...@googlegroups.com
Hello,

Thanks for your answer, I will have a look and investigate your solution further.
I also thought there could be a way to achieve this kind of behavior using annotation and interceptors, but for some reasons I am a bit shy when it comes to AOP stuff.

Best

On Thursday, July 19, 2012 4:50:39 PM UTC+2, christia...@ircm.qc.ca wrote:

Sorry, I didn’t read your question correctly.

 

But my point is still valid. By using a custom interceptor you can handle the exception the way you like and MyBatis-Guice interceptor will still work its magic.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybatis-user@googlegroups.com] De la part de Poitras Christian


Envoyé : July-19-12 10:48 AM
À : 'mybati...@googlegroups.com'
Objet : RE: Mybatis-guice, configuring default exception type for @Transactional

 

Hi,

 

In such a case, it may be better to add an your own rethrow interceptor over @Transactional.

That way, you don’t have to modify every @Transactional annotations and it’s easier to maintain.

 

Christian

 


Envoyé : July-19-12 5:14 AM
À : mybati...@googlegroups.com
Objet : Mybatis-guice, configuring default exception type for @Transactional

Poitras Christian

unread,
Jul 25, 2012, 8:57:11 AM7/25/12
to mybati...@googlegroups.com

I agree. Interceptors seems non-trivial at first and you may encounter some problems because it usually creates proxies.

But once you taste it, it becomes addictive!

 

The main thing you must keep in mind with MyBatis-Guice @Transactional is that the annotation will only work on methods that can be overridden by a subclass. So only use @Transactional on public or protected methods.

Don’t use @Transactional on private methods. That doesn’t work. I haven’t tested on package methods.

 

This also applies to any interceptor you use with Guice or Spring.

 

As an additional hint, remember that if you annotate an interface method but not its actual implementation, you will need to check for the annotation recursively one the parents. I doubt Guice will check parent annotations for you.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Stephane C.
Envoyé : July-25-12 3:23 AM
À : mybati...@googlegroups.com
Objet : Re: Mybatis-guice, configuring default exception type for @Transactional

 

Hello,

 

Thanks for your answer, I will have a look and investigate your solution further.

I also thought there could be a way to achieve this kind of behavior using annotation and interceptors, but for some reasons I am a bit shy when it comes to AOP stuff.

 

Best


On Thursday, July 19, 2012 4:50:39 PM UTC+2, christia...@ircm.qc.ca wrote:

Sorry, I didn’t read your question correctly.

 

But my point is still valid. By using a custom interceptor you can handle the exception the way you like and MyBatis-Guice interceptor will still work its magic.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Poitras Christian


Envoyé : July-19-12 10:48 AM
À : 'mybati...@googlegroups.com'
Objet : RE: Mybatis-guice, configuring default exception type for @Transactional

 

Hi,

 

In such a case, it may be better to add an your own rethrow interceptor over @Transactional.

That way, you don’t have to modify every @Transactional annotations and it’s easier to maintain.

 

Christian

 


Envoyé : July-19-12 5:14 AM
À : mybati...@googlegroups.com
Objet : Mybatis-guice, configuring default exception type for @Transactional

Reply all
Reply to author
Forward
0 new messages