I have a very similar problem to the one described here
http://forum.hibernate.org/viewtopic.php?p=2376516#2376516. My parent class has a collection of elements:
Code:
@CollectionOfElements
@JoinTable(name="renewal",
joinColumns = @JoinColumn(name="institution_id"))
@IndexColumn(name="ndx", base=0)
@ForeignKey(name="fk_renewal_institution")
private List<Step> renewals = new ArrayList<Step>();
The embeddable Step class contains an entity reference, to a Comment instance:
Code:
@Embeddable
public class Step {
...
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="comment_id", nullable=false)
private Comment comment;
The Comment class is an entity:
Code:
@Entity
@Table(name="aml_comment")
public class Comment {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="commentSequence")
@SequenceGenerator(name="commentSequence", sequenceName="seq_comment", allocationSize=1)
private int id;
@Column(length=1000)
private String text;
/** time the comment was entered */
@Column(name="time_of", nullable=false)
private Date when;
...
The Step class includes a cascade for its contained entity. When a new Step is added and I try to update the parent class I get an exception:
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.visa.aml.domain.Comment
Does anyone know why this might happen? I was hopeful that the above posting might hold the answer. I think my parent/child relationship and annotations are now similar to that code, but I still get the exception. I am using the Spring HibernateTemplate class in my DAO to do the update. Perhaps the difference in my case is that the parent is already persistent and the new child is transient, so I call the saveOrUpdate() method to try write both to the database. Any insight would be greatly appreciated.