Re: Modify implementations of the interfaces using MapperScannerConfigurer???

22 views
Skip to first unread message

Guy Rouillier

unread,
Oct 28, 2012, 3:10:03 PM10/28/12
to mybati...@googlegroups.com
On 10/27/2012 12:08 PM, Kilian wrote:
> Hi all,
>
> I'm trying to create an example project where I use different ORMs
> implementations of a given interface. I've already created one for jpa,
> hibernate and jdbc but I have problems with the one with MyBatis.
> For what I want, I need to modify return types of some of the methods
> created by MyBatis. I've already created an interface with annotations
> for one of my models and it works but I need the insert statement to
> return the object created with its autogenerated id, not the number of
> rows modified. It'd be great if it was possible to override the
> implementation created by MyBatis of this interface so I could add some
> behaviour after each method created. Is this possible?

We just implemented a wrapper class around the MyBatis interface class
that adds any additional behavior desired. If the app doesn't need any
additional behavior for a particular mapper method, it can invoke the
mapper interface directly; or if you prefer to maintain consistency, in
such cases, your wrapper class method is a sample "return mapper.method()".

--
Guy Rouillier

Paul Krause

unread,
Oct 28, 2012, 5:04:12 PM10/28/12
to mybati...@googlegroups.com
Why do you need to return the object from the insert?  I'm pretty sure JDBC doesn't do this.
Besides, the object you passed to insert should have been updated with the generated key.


On Saturday, October 27, 2012 12:08:02 PM UTC-4, Kilian wrote:
Hi all, 

I'm trying to create an example project where I use different ORMs implementations of a given interface. I've already created one for jpa, hibernate and jdbc but I have problems with the one with MyBatis.
For what I want, I need to modify return types of some of the methods created by MyBatis. I've already created an interface with annotations for one of my models and it works but I need the insert statement to return the object created with its autogenerated id, not the number of rows modified. It'd be great if it was possible to override the implementation created by MyBatis of this interface so I could add some behaviour after each method created. Is this possible?

Thank you in advance!!

Kilian

unread,
Oct 29, 2012, 5:19:24 AM10/29/12
to mybati...@googlegroups.com
Thanks for the tip! I was blind looking for a way to invoke mybatis directly in my method when there was a solution as simple as that. I've already tried it and it works perfectly. 
Thank you again!

Kilian

unread,
Oct 29, 2012, 5:21:45 AM10/29/12
to mybati...@googlegroups.com
My problem is I want to keep consistency with my other implementations and I know I will need to wrap the method latter in the future with other behaviors.
That's the reason I wanted to do this. I've already found the solution with the idea from Guy in the previous reply. But thanks anyway :)
Reply all
Reply to author
Forward
0 new messages