Posts

Showing posts with the label spring-data

How to update an object with another object value in JPQL using Spring JPA

Image
Clash Royale CLAN TAG #URR8PPP How to update an object with another object value in JPQL using Spring JPA I'm facing a problem in JPQL. I have two entities like below class Employee{ private Long id; private String name; private Department department; public void setId(Long id){ this.id = id; } public void setName(String name){ this.name = name; } public void setDepartment(Department department){ this.department = department } public Long getId(){ return this.id; } public String getName(){ return this.name; } public Department getDepartment(){ return this.department; } } and... class Department{ private Long id; private String name; public void setId(Long id){ this.id = id; } public void setName(String name){ this.name = name; } public Long getId(){ return id; } public String getName(){ return name; } } Now i need to update an Employee 's department. I have tried the query below. Employee ...

how to use SpringData findAll() between select when using an object as major condition?

Image
Clash Royale CLAN TAG #URR8PPP how to use SpringData findAll() between select when using an object as major condition? So there's a method in SpringData findAll(Pageable pageable,Condition condition) ; , usually I use it like findAll(pageable,myobject) . findAll(Pageable pageable,Condition condition) ; findAll(pageable,myobject) The question is when it comes to select some records between some certain field range ,like select out objects whose createDate are between A and B , how to use findAll() ? findAll() I tried findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b) ; findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b) But here I can't put myObj as a condtion into the method , and it caused a lot trouble when some fields in the myObj are not sure if it would be used as a condition. 1 Answer 1 You can simply use JPA Specification to do t...