-->
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: Entity contained in embedded component doesn't persist
PostPosted: Fri Feb 15, 2008 1:47 pm 
Newbie

Joined: Wed Jan 24, 2007 3:37 pm
Posts: 4
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.


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.