I have class City which is:
@Entity
@Table(name="city",schema="rezervisi")
public class City {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private int id;
@Getter
@Setter
@NotBlank(message = "Name is mandatory")
private String name;
}
Now I want to override save method in which I send object city. How can I do it if i want to send whole object and not @Params separately. And also since ID is generated how I handle it through parameter here?
Code for repository class is:
public interface CityRepo extends JpaRepository<City,Integer> {
@Query(value="select id, name from city where id = :id ", nativeQuery = true)
Optional<City> findById(Integer id);
@Query(value="select id, name from city where name = :name ", nativeQuery = true)
City findByName(String name);
@Modifying
@Query(value = "insert into city (id,name) VALUES (:id,:name)", nativeQuery = true)
City save(City city ); // instead City save(@Param("id) int id ....
void delete(City city);
}