各位好 ,想請問一下各位大大
我在實作一對多雙向關聯的時候,發現如果我在一方設置
@GeneratedValue(strategy = GenerationType.AUTO)
的時候如果我在 service 內 新增多方的資料 不會跳error 只會將資料庫的sequence 遞增就卡住了,但也沒跳出錯誤
想請問各位大大該如何解決呢?
以下為insert 的service
@Override
public void createUserHobbyAndSkills(int userId, HobbyAndSkillDto hobbiesAndSkills) {
List<String> hobbiesList = hobbiesAndSkills.getHobbies();
List<String> skillList = hobbiesAndSkills.getSkills();
List<UserHobby> userHobbies = new ArrayList<UserHobby>();
List<UserSkill> userSkills = new ArrayList<UserSkill>();
User uid = new User();
uid.setUserId(userId);
for (int i = 0; i < hobbiesList.size(); i++) {
UserHobby hobby = new UserHobby();
hobby.setHobby(hobbiesList.get(i));
hobby.setUser(uid);
userHobbies.add(hobby);
}
userHobbiesDao.saveAll(userHobbies);
}
感謝各位