Greetings,
I have a many-to-one relationship, which when I attempt saving, generates "PersistentObjectException: detached entity passed to persist", even when unmodified. The Cluster object contains the list of Component objects. Initially, I was adding components to the list and was getting PersistentObjectException, so I attempted to save the retrieved object without altering and I'm still getting the exception.
Cluster cluster = clusterDao.findbyId(id); // cluster.getComponens().add(component); entityManager.merge(cluster);
The relationship is defined as
@Entity @Table(name = "CLUSTERS_T") public class Cluster extends BaseEntity implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="CLUSTER_ID_SEQ") @SequenceGenerator(name="CLUSTER_ID_SEQ", sequenceName="IRG_CLUSTER_ID_SEQ",allocationSize=1) @Column(name="CLUSTER_ID") private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy="cluster", targetEntity=Component.class) @JoinColumn(name="CLUSTER_ID", referencedColumnName="CLUSTER_ID") private List<Component> components; .... }
@Entity @Table(name = "CLUSTER_COMPONENTS_T", uniqueConstraints =@UniqueConstraint(columnNames={"CLUSTER_ID", "SRG_CODE", "SRG_FLEX", "SRA_DESIGNATOR", "SRA_FLEX"})) public class Component extends BaseEntity implements Serializable{ private static final long serialVersionUID = 9192345415949493620L; @Id @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="COMPONENT_ID_SEQ") @SequenceGenerator(name="COMPONENT_ID_SEQ", sequenceName="CLUSTER_COMPONENTS_ID_SEQ",allocationSize=1) @Column(name = "CLUSTER_COMPONENT_ID", nullable = false) private Long clusterComponentID; @Column(name="CLUSTER_ID", length=9, nullable=false, insertable=false, updatable=false) private Long clusterId; .... @ManyToOne() @JoinColumn(name="CLUSTER_ID", referencedColumnName="CLUSTER_ID") private Cluster cluster; .... }
Any suggestions why can't I save even unmodified object? Any suggestions are greatly appreciated.
-aaton
|