-->
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: @OneToMany stacktrace with insertions
PostPosted: Thu Apr 21, 2011 5:45 am 
Newbie

Joined: Thu Apr 21, 2011 5:31 am
Posts: 9
In my project: Spring Web MVC with OpenSessionInViewFilter,
I have the following code in my obect (Event):
Code:
@JoinTable(
           name = "subscription_histories",
           joinColumns = @JoinColumn(name = "event_id"),
           inverseJoinColumns = @JoinColumn(name = "subscription_history_id")          
)
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch=FetchType.LAZY)
//@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@LazyCollection(value = LazyCollectionOption.TRUE)
public Set<SubscriptionHistory> getSubscriptionHistories() {
   return this.subscriptionHistories;
}

The relation is unidectional

If I save new Event with:
Code:
      Event event = (Event) object;
      Session session = getSessionFactory().getCurrentSession();
      try {
         Transaction transaction = session.beginTransaction();
         if (event.getId() > 0) {
            session.merge(event);
         } else {
            session.saveOrUpdate(event);
         }
         transaction.commit();
      }catch(.........


I get:
Code:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: .....SubscriptionHistory


If I remove the comments at @Cascade I get another Exception:
Code:
org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions


What am I doing wrong?

NB: Saving a new Event with no SubscriptionHistory references works okay, and adding these to an existing Event also works fine


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.