0

私はこのコードを持っています:

Candidate candidate = new Candidate();
candidate.setName("testUser");
candidate.setPhone("88888");
candidateService.add(candidate);
sessionFactory.getCurrentSession().flush();
return candidate;

としてマークされた CandidateService @Transactional;

candidateService.add(candidate); 候補の実行後に ID フィールド値を取得する理由を説明していただけますか。もしかして普通ですか?

candidateService.add(candidate) realization:

public void add(Candidate candidate) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String login = auth.getName();
     User user =  utilService.getOrSaveUser(login);
     candidate.setAuthor(user);
     candidateDao.add(candidate);
}

@Override
public Integer add(Candidate candidate) throws HibernateException{
    Session session = sessionFactory.getCurrentSession();
    if (candidate == null) {
        return null;
    }
    Integer id = (Integer) session.save(candidate);
    return id;

}

候補が持続状態にある場合に起こると思いました。

私は台無しにしました。

4

1 に答える 1