java EM不会持久化到数据库中
我正在使用SpringBoot并尝试将新对象持久化到db,但什么也没发生。对于另一个实体,我得到了相同的方法,它是有效的。有什么建议吗
实体:
@Entity
@Table(name = "subject")
public class Subject implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "subject")
private Set<Question> questions =new HashSet<>();
DAO:
import org.springframework.transaction.annotation.Transactional;
@Autowired
private EntityManager entityManager;
@Repository
@Transactional
public class QuestionDaoImpl implements QuestionDao {
public void createNewSubjectByName(String name) {
Subject subject = new Subject();
subject.setName(name);
entityManager.persist(subject);
}
# 1 楼答案