spring - Update or SaveorUpdate in CRUDRespository, Is there any options available -


i trying crud operations entity bean. crudrepository provide standard methods find, delete , save there no generic method available saveorupdate(entity entity) in turn calls hibernate or hibernatetemplate sessions saveorupdate() methods.

the way crudrepository provides functionality use this

@modifying @query("update space c set c.owner = :name c.id = :id") integer setnameforid(@param("name") string name, @param("id") 

but not generic , needs written complete form fields. please let me know if there way or can session of hibernate or object of spring hibernatetemplate solve issue.

the implementation of method

<s extends t> s save(s entity)

from interface

crudrepository<t, id extends serializable> extends repository<t, id>

automatically want. if entity new call persist on entity manager, otherwise call merge

the code looks this:

public <s extends t> s save(s entity) {      if (entityinformation.isnew(entity)) {         em.persist(entity);         return entity;     } else {         return em.merge(entity);     } } 

and can found here. note simplejparepository class automatically implements crudrepository in spring data jpa.

therefore, there no need supply custom saveorupdate() method. spring data jpa has covered.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -