Java @“一夫一妻关系”;“一”;id未持久化

Java @“一夫一妻关系”;“一”;id未持久化,java,hibernate,jakarta-ee,jpa,Java,Hibernate,Jakarta Ee,Jpa,这是我的“标题”实体: 我有一个共同的情况: Documento d = new Documento(); // various Documento settings List<RigaDocumento> rows; // creation of rows d.setRighe( rows ); ? 为什么因为它是关系的拥有方。理想情况下,Documento中应该有一个addRow()方法,该方法可以添加要设置的行,还可以设置该行的文档。是的,必须这样做,因为您有一个双向关联,并

这是我的“标题”实体:

我有一个共同的情况:

Documento d = new Documento();
// various Documento settings
List<RigaDocumento> rows;
// creation of rows
d.setRighe( rows );
?


为什么因为它是关系的拥有方。理想情况下,Documento中应该有一个
addRow()
方法,该方法可以添加要设置的行,还可以设置该行的文档。

是的,必须这样做,因为您有一个双向关联,并且关联的所有者端是RigaDocumento。所有者端是不具有
mappedBy
属性的端。另一侧称为反向侧,被JPA/Hibernate忽略

@Entity
@Table(name="righe_documenti")
public class RigaDocumento implements Serializable {

@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @ManyToOne
    private Documento testataDocumento;

//...
}
Documento d = new Documento();
// various Documento settings
List<RigaDocumento> rows;
// creation of rows
d.setRighe( rows );
row.setTestataDocumento(d);