我有几个成员类,以及相关的getter和setter方法:如何通过RestTemplate通过嵌入式成员进行POST?
public class Tester implements Serializable {
@Column(name="ID", nullable=false, unique=true)
@Id
@GeneratedValue(generator="LOCATION_FACILITYTYPE_ID_GENERATOR")
@org.hibernate.annotations.GenericGenerator(name="LOCATION_FACILITYTYPE_ID_GENERATOR", strategy="native")
private int ID;
@Column(name="Value", nullable=false, unique=true, length=4)
private String value;
@Column(name="Name", nullable=false, unique=true, length=8)
private String name;
@ManyToOne(targetEntity=location.FacilityType.class, fetch=FetchType.LAZY)
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
@JoinColumns({ @JoinColumn(name="FacilityTypeID", referencedColumnName="ID", nullable=false) })
private location.FacilityType facility;
在JUnit中,我试图测试创建一个测试元素:
Tester trythis = new Tester();
trythis.setName("Herewe");
trythis.setValue("wow1");
Tester jnode = restTemplate.postForObject(TestBase.URL + "tester/", trythis, Tester.class);
可正常工作。但是,如果我用这样的代码,包括嵌入式成员:
FacilityType ft = new FacilityType();
ft.setValue("AL");
ft.setName("2adamlec");
Tester trythis = new Tester();
trythis.setName("Herewe");
trythis.setValue("wow1");
trythis.setFacility(ft);
Tester jnode = restTemplate.postForObject(TestBase.URL + "tester/", trythis, Tester.class);
其中具有价值内嵌构件= AL还没有出现在数据库中,我仍然得到的测试表中创建一个新的行.. 。但测试人员的值和名称列填充了为FacilityType定义的值(AL和2adamlec)。
请注意,我们正在使用FacilityType和Tester的JPARepository框架。 CRUD功能因此在“封面”下处理,我无法调试POST处理。我想知道这是否与GET测试人员数据只会返回JSON回复中的原始字段相关,因为没有为FacilityType定义投影。
我做错了什么导致FacilityType字段被保存来替代Tester表中所需的Tester字段?