I've done some research on my own and understand the basic concept. But some insights can only be gained through actual experience.What are the advantages of myBatis that would make it worth learning a new framework?In what case would you avoid using it?
What are the advantages of myBatis over Hibernate?
orm;database development;hibernate
Consider what you're trying to achieve. Typically, the Command Query Response Segregationmodel works well for complex domains.The reason is that you're trying to do one of two things typically:Create/Update/Delete some complex domain entitiesRun analytic fetch queries (i.e. summation/aggregation queries)Hibernate works well for case 1 allowing you to just make a POJO and persist/update it. It also does this quickly, unless your domain is quite large.myBatis is great for fetch queries (case 2) where you just want an answer. Hibernate would attempt to load the entire object graph and you'd need to start tuning queries with LazyLoading tricks to keep it working on a large domain. This is important when running complex analytic queries that don't even return entity objects. Hibernate only offers SqlQuery and bean Transformers in this case with huge default types like BigDecimal, while myBatis could easily map to a simple POJO non-entity.These two cases are the difference between Commands where you want to change the domain data and Responses where you just want to fetch some data.So, consider these two cases and what your application does. If you have a simple domain and just fetch information, use myBatis. If you have a complex domain and persist entities, use Hibernate. If you do both, consider a hybrid approach. That's what we use on our project that has thousands of entities to keep it under control. ;)