Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate集合在更新时为空_Java_Hibernate_Jpa_Orm_Hibernate Mapping - Fatal编程技术网

Java Hibernate集合在更新时为空

Java Hibernate集合在更新时为空,java,hibernate,jpa,orm,hibernate-mapping,Java,Hibernate,Jpa,Orm,Hibernate Mapping,考虑以下几点: @Entity public class MainEntity { @OneToOne(orphanRemoval = true, cascade = CascadeType.ALL) private ChildEntity childEntity; } @Entity public class ChildEntity { @OneToMany(cascade = CascadeType.ALL) @LazyCollection(FALS

考虑以下几点:

@Entity
public class MainEntity {


    @OneToOne(orphanRemoval = true, cascade = CascadeType.ALL)
    private ChildEntity childEntity;
}

@Entity
public class ChildEntity {


    @OneToMany(cascade = CascadeType.ALL)
    @LazyCollection(FALSE)
    private List<AnotherEntity> otherEntities;
}
一切都很好,然后我做了一些更新,在交易结束后很久

final ChildEntity anotherNewChild = new ChildEntity();
anotherNewChild.addOtherEntity(anotherEntity); //Several Entities can be added here
mainEntity.setChildEntity(anotherNewChild);

//A log of LOG.info(mainEntity); shows all fields appropriately set
//At some point during merge operation, the new ChildEntity will need to be persisted.
 //According to my logs, an invocation of EntityManager.persist(anotherNewChild) occurs, during as the merge is propagated to the new entity.
//At this point is where the ChildEntity.otherEntities is detected to be null
return EntityManager.merge(mainEntity); 
问题是,使用persist时

列表

在Hibernate问题跟踪程序上打开了一个问题


问题是merge返回一个新实体,因此您应该执行以下操作:

mainEntity = EntityManager.merge(mainEntity);

我就是这么做的。因为我执行远程ejb调用,所以我不会返回除此之外的任何内容。请看我对这个问题的编辑
mainEntity = EntityManager.merge(mainEntity);