java - Spring - migrate from DAO-Service architecture to JPA -


i have web mvc written using spring. used separate dao , service classes.

my old code:

@repository public class roledaoimpl implements roledao { ... }  @service @transactional public class rolemanagerimpl implements rolemanager { ... }  @controller public class homecontroller {     @autowired     private rolemanager rolemanager; ... } 

now try spring jpa. can't rewrite testing project dao-service spring jpa.

there project source on github https://github.com/martin159/springjpa

after run project following error:

warn : org.springframework.web.context.support.xmlwebapplicationcontext - exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in servletcontext resource [/web-inf/spring-servlet.xml]: invocation of init method failed; nested exception java.lang.illegalargumentexception: no persistenceprovider specified in entitymanagerfactory configuration, , chosen persistenceunitinfo not specify provider class name either     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1568)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:540)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:302)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:229)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:298)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193)     @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:956)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:747)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480)     @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403)     @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306)     @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106)     @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4961)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5455)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:901)     @ org.apache.catalina.core.containerbase.addchild(containerbase.java:877)     @ org.apache.catalina.core.standardhost.addchild(standardhost.java:634)     @ org.apache.catalina.startup.hostconfig.deploydescriptor(hostconfig.java:671)     @ org.apache.catalina.startup.hostconfig$deploydescriptor.run(hostconfig.java:1840)     @ java.util.concurrent.executors$runnableadapter.call(executors.java:511)     @ java.util.concurrent.futuretask.run(futuretask.java:266)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)     @ java.lang.thread.run(thread.java:745) caused by: java.lang.illegalargumentexception: no persistenceprovider specified in entitymanagerfactory configuration, , chosen persistenceunitinfo not specify provider class name either     @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:323)     @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:318)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1627)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1564)     ... 25 more error: org.springframework.web.context.contextloader - context initialization failed 

i spend lot of hours spring jpa, still can't fix it.

do have idea bad?

i think because specified localcontainerentitymanagerfactorybean without telling spring what's persistence unit name is. hence spring use default one.

<bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> 

meanwhile in persistence.xml, specified persistence unit name springjpa

<persistence-unit name="springjpa" transaction-type="jta"> 

try

<bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">   <property name="persistenceunitname" value="springjpa"/> </bean> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -