小编Gor*_*ora的帖子

JPA坚持有一对多关系的父母和孩子

我想用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循环?这可行吗?有没有其他方式或配置,我可以自动坚持父母和孩子?

jpa one-to-many

18
推荐指数
3
解决办法
4万
查看次数

未捕获的TypeError:无法读取未定义的common.js的属性"x"

我正在使用谷歌地图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)

问题是什么?另外我该如何解决?

javascript google-maps-api-3

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-maps-api-3 ×1

javascript ×1

jpa ×1

one-to-many ×1