public interface PersonService {
Person getUser(Integer id);
void addUser(Person person);
@Transactional
void updateUserName(String name);
}
@Entity
@Table(name = "person")
public class Person {
@Id
@SequenceGenerator(name = "person_id_seq",
sequenceName = "person_id_seq", allocationSize = 1)
@GeneratedValue(generator = "person_id_seq", strategy = GenerationType.SEQUENCE)
private Integer id;
@Column(name = "name")
private String name;
@OneToMany()
@JoinColumn(name = "company_id")
private List<Person> personList;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "company_id")
private List<Person> personList;
public interface PersonRepository extends JpaRepository<Person, Integer> {
Person findById(Integer id);
@Modifying
@Query("update Person p set p.name = :name where p.id = :id")
void updatePersonName(@Param("name") String name, @Param("id") Integer id);