0

I am trying to get this answered, and found one comment in the MyBatis documentation:

Usually MapperFactoryBean is preferred to this class, since it requires no extra code. But, this class(DAO) is useful if you need to do other non-MyBatis work in your DAO and concrete classes are required and use SqlSessionDaoSupport or SqlSessionFactory

In case I chose to use MapperFactoryBean today in my project, but later I would need to use concrete DAO (may be because you may not do 100% using SQLs in mapper), then I need to change the design.

If the above is true, then MapperFactoryBean would be very less useful and would never(or mostly) be a choice.

In other words: Can MapperFactoryBean and DAO co-exists? Even if yes, should they be?

Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
  • Why are you thinking this? And what is your question? – Kai May 27 '13 at 19:18
  • My Questions is: In case I am using a Mapper, and I would need to create some dynamic SQL (which may me outside of MyBatis Support), I would end up using DAO. So why not use DAO as design choice at first place even you have a slight chances of having the requirement? – Sandeep Jindal May 27 '13 at 19:24

2 Answers2

1

Are you aware of what this "non-MyBatis work" or "some dynamic SQL" how you call it exactly is? Well I'm not. But assuming writing Mappers is much faster and more intuitive for your developers you are saving a lot of time here. And when there are some scary non-MyBatis things to do why not writing then a very specific DAO which only does this one non-MyBatis thing?

Kai
  • 38,985
  • 14
  • 88
  • 103
  • Why not write DAO(in case you want a scary non-MyBatis) is that I need to change the whole service to change to DAO instead of existng mapper. – Sandeep Jindal May 27 '13 at 19:54
  • @SandeepJindal No what I'm saying is that both can exist next to each other. – Kai May 27 '13 at 19:56
  • Right, probably, this is the right question: "Can MapperFactoryBean and DAO co-exists? Even if yes, should they be?" I have updated the question also. – Sandeep Jindal May 27 '13 at 19:58
0

+1 for coexistence ( DAO is not a must ! ) This is especially true if you are using mybatis in spring framework.

As for the refactoring part, it's good if you have incorpoproate a suitable testing framework to help out.

Ian Lim
  • 4,164
  • 3
  • 29
  • 43