spring - Using JpaRepository instead of CrudRepository -


i've read if possible should use crudrepository or pagingandsortingrepository on jparepository don't couple code store-specific implementation, there instance jparepository better choice?

for application, need use saveandflush() method , flush() method flush database changes right away because trying merge 2 entities , don't want run errors unique key conditions.

for example:

public class user {     @id     string userid;      @onetomany(mappedby = "user")     private collection<address> addresses;      // getter , setter methods }  public class address {      @manytoone(optional = false)     private  user user;      // other fields     // getter , setter methods }  public void mergeduplicateuseraddresses(user user, user duplicateuser) {     string userid = user.getuserid();     list<address> addresses = duplicateuser.getaddresses()      (address address : addresses) {         address.setuser(userid);         addressesrepository.saveandflush(address);     } } 

for instance, see using jparepository on crudrepository, there alternative make less store-specific?

just use jparepository , happy it. change of underlying data source type in realtiy rare case , when happens there larger changes necessary anyways. different data source types need in reality different handling. know happens guys says should abstract type of data source can change easily. not sure if ever tried it.

some arguments why not work (in case need argue someone)

  • change of underlying relational database not work. yes jpa should abstraction layer it, not work in every case. run troubles when change jpa provider. have characteristics.
  • when swap date source f.e. relational noe4j. do @query stuff. sorry have neo4j not understand sql.
  • transaction handling have keep in mind. data source supports transactions @ , how behave. example relation , neo4j. both have transaction system, work complelty different , can run troubles when migrate code directly neo4j. reason neo4j has more strict locking behaviour.
  • your business layer may depend performance reason on specific fetching behaviour, happens if swap data source type. these different data source types support alternative fetching behaviours. or necessary modify how business layer works @ because of that?

and of story. change of data source type means more troubles implementing different interface.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -