Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA & MyBatis

I am trying to use Spring Data JPA with MyBatis. Since there isnt a Vendor Adapter for MyBatis, what is the alternative here?

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.abc.xyz.domain"/>
</bean>

I am getting the below exception when I tried to initialize my application.

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No PersistenceProvider specified in EntityManagerFactory configuration, and chosen PersistenceUnitInfo does not specify a provider class name either

Thanks

like image 573
srini Avatar asked Nov 11 '15 14:11

srini


2 Answers

Mybatis does not implement JPA. Mybatis is not ORM Framework. JPA is ORM Specification which is implemented by Hibernate, Toplink, Eclipselink . Since Mybatis does not mplement JPA, it does not come under the list of JPA providers. Hence, you cannot use mybatis as a JPA framework. Mybatis is a data mapper framework which is completely different framework compared to JPA. In JPA and ORM frameworks, you map Objects /Entities to the corresponding sql tables and you work on objects and not on tables directly unless you use their native queries. In mybatis , you play directly with sql data.. Hope this clears the difference between mybatis and JPA. Hence when you want mybatis with spring data you use spring data mybatis independently and not spring data JPA.

like image 117
Pankaj Shet Avatar answered Sep 27 '22 19:09

Pankaj Shet


Why not try spring-data-jpa-extra

It provide a dynamic query solution for spring-data-jpa like mybatis, but much easier than mybatis.

I think you would like it : )

like image 30
stormning Avatar answered Sep 27 '22 20:09

stormning