我想用20个子实体来持久保存父实体,我的代码如下
家长班
@OneToMany(mappedBy = "parentId")
private Collection<Child> childCollection;
Run Code Online (Sandbox Code Playgroud)
儿童班
@JoinColumn(name = "parent_id", referencedColumnName = "parent_id")
@ManyToOne(optional=false)
private Parent parent;
Run Code Online (Sandbox Code Playgroud)
String jsonString = "json string containing parent properties and child collection"
ObjectMapper mapper = new ObjectMapper();
Parent parent = mapper.readValue(jsonString, Parent.class);
public void save(Parent parent) {
Collection<Child> childCollection = new ArrayList<>() ;
for(Child tha : parent.getChildCollection()) {
tha.setParent(parent);
childCollection.add(tha);
}
parent.setChildCollection(childCollection);
getEntityManager().persist(parent);
}
Run Code Online (Sandbox Code Playgroud)
所以,如果有20个子表,那么我必须在每个子表中设置父引用,因为我必须写20个for循环?这可行吗?有没有其他方式或配置,我可以自动坚持父母和孩子?
我正在使用谷歌地图api v3并在使用时遇到此错误
map.fitBounds(边界); 功能
以下是代码:
var arr = [{lat: -25.363, lng: 131.044}, {lat: 12.97, lng: 77.59}];
for (i = 0; i < arr.length; i++) {
bounds.extend(new google.maps.LatLng(arr[i]));
}
map.fitBounds(bounds); //If I comment this line in m code, the error is gone but map does not load.
Run Code Online (Sandbox Code Playgroud)
问题是什么?另外我该如何解决?