Hibernate inserts duplicates into a @OneToMany collection

前端 未结 5 1637
野性不改
野性不改 2020-12-01 20:52

I have a question concerning Hibernate 3.6.7 and JPA 2.0.

Consider following entities (some getters and setters are omitted for brevity):

@Entity
pub         


        
5条回答
  •  借酒劲吻你
    2020-12-01 21:39

    By using Java enterprise context in Wildfly (8.2.0-Final) (I think it's Hibernate version 4.3.7) the workaround for me was, to first persist the child an the add it to the lazy collection:

    ...
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void test(){
        Child child = new Child();
        child.setParent(parent);
        childFacade.create(child);
    
        parent.getChildren().add(cild);
    
        parentFacade.edit(parent);
    }
    

提交回复
热议问题