Reputation: 298
I'm trying to use JPA (@CrudRepository), but I want to create also my custom controller with Mybatis.
I have that working, but the problem is that for example in procedures, they don't work together.
Is it possible to implement JPA with Mybatis to work together?
I've been reading a lot, I understand that Mybatis is not ORM. Some blogs indicate that it's possible, but not how.
Upvotes: 1
Views: 3624
Reputation: 4274
It's possible to manage the both JPA and mybatis together under Spring Transaction. Both of them, in fact, can be rollback together within the same transaction. However, do take note of side effects such as:
e.g.
Within the same transaction:
// Perform insert and expect id to be returned
TableA tableA = new TableA();
jpaRepositoryForTableA.save( tableA );
// Use the tableA in the next mybatis mapper
TableB tableB = new TableB();
tableB.setTableAId( tableA.getId() );
this.mapper.saveTableB( tableB )
In the scenario above, TableB will not be able to get the TableA's ID.
Upvotes: 1
Reputation: 24591
I don't think it's good idea at all. Use one or the other.
I can imagine that you could make it working, but your can't use them on top of same tables or use transaction management for both persistence frameworks.
So if you have such use case (you didn't explain any), I would argue that your application should be split into two separate services. Optionally consider to separate your storage into two separate DB instances.
Upvotes: 0