我正在使用休眠来持久化实体。但是,即使实体包含指定的字段值,数据也将以null形式持久保存。
@RestController
@RequestMapping("example")
public class Controller {
@Autowired
EntityManager entityManager;
@RequestMapping("/getData")
@Transactional
public void getData() {
Members member = new Members();
member.firstName= "SRC";
member.lastName = "Code";
member.major = "Computer Science";
member.ID = 424;
entityManager.persist(member);
}
会员班
@Entity
@Table(name = "members")
public class Members {
@Id
public int ID;
public String major;
@Column(name = "firstName" , nullable = false)
@Length(min = 0, max =20)
public String firstName;
@Length(min = 0, max =20)
@Column(name = "lastName" , nullable = false)
public String lastName;
}
但是数据库表中的数据正在获取firstName和LastName fields. But the ID and major is correctly persisted.
的空值