-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: PersistentObjectException even for unmodified object
PostPosted: Fri Mar 12, 2010 9:29 am 
Newbie

Joined: Thu Mar 11, 2010 1:47 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.