spring - save operation in jpa data repository doesn't work when define mutiple @EnableJpaRepositories classes -


i researching on usage of spring data jpa. appreciated if can check wrong.

i created 2 jpa repositories: apirepository , clientrepository in 2 different packages , created 2 configuration classes configure these 2 repositories using @enablejparepositories annotation respectively.

when spring application calls these 2 repositories' save() methods @ same time, apirepository.save() fail, without exception. if move @primiary annotation (this avoid nouniquebeandefinitionexception) apiappconfig class, clientrepository.save fail without exception. opened sql log, no update sql executed failing method.

did hit such situation? how use spring data jpa?

apirepository

package test.api;  public interface apirepository extends repository<api, long>{  .... } 

apiappconfig

package test.api;  @configuration @componentscan(basepackages = "test.api") @enablejparepositories(         basepackages = "test.api.repository",          entitymanagerfactoryref = "apientitymanagerfactory",         transactionmanagerref="apitransactionmanager",         enabledefaulttransactions=true ) @enabletransactionmanagement public class apiappconfig {     @bean     public localcontainerentitymanagerfactorybean apientitymanagerfactory(){      ...     }      @bean     public platformtransactionmanager apitransactionmanager() {     ...     }      @bean     public datasource apidatasource() {     ...     } } 

apiservice

package test.api;  @service public class apiservice {      @autowired     private apirepository apirepository;       public api findone(long id){         return apirepository.findone(id);     }      @transactional("apitransactionmanager")     public void updateone(api api){         apirepository.save(api);     } } 

clientrepository

package test.client;  public interface  clientrepository extends repository<client, long>{    ... } 

clientappconfig

package test.client;  @configuration @componentscan(basepackages = "test.client") @enablejparepositories(         basepackages = "test.client",         entitymanagerfactoryref = "entitymanagerfactory",         transactionmanagerref="transactionmanager",         enabledefaulttransactions=true )  @enabletransactionmanagement public class clientappconfig {      @bean     @primary     public localcontainerentitymanagerfactorybean entitymanagerfactory() {        ...     }      @bean     public platformtransactionmanager transactionmanager() {      ...     }      @bean     @primary     public datasource datasource() {     ...     } } 

clientservice

package test.client;  @service public class clientservice {      @autowired     private clientrepository clientrepository;       public daotest findone(long id){         return clientrepository.findone(id);     }      @transactional("transactionmanager")     public void updateone(client client){         clientrepository.save(client);     } } 

in apiappconfig class have set

@enablejparepositories(     basepackages = "test.api.repository",  

but apirepository in package test.api , not in test.api.repository, @ least can see in apirepository class source code.

so either change basepackages value reflect correct one, or move apirepository inside test.api.repository package


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -