-->
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: Newbie: Error with Adding to One-to-Many collection
PostPosted: Fri Jan 21, 2005 3:30 am 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
Hi all,

I am receiving an error when I am trying to add to a collection. So, I have two objects: Consumer and Toys.

The relationship between Consumer and Toys is one-to-many, so the object Consumer has a Set of toys. Here is a code snippit of the class definition of Consumer:

Code:
   /**
    * @hibernate.set role="toys" table="TOY"
    *                cascade="all" readonly="true"
    * @hibernate.collection-key column="CONSUMER_ID"
    * @hibernate.collection-one-to-many
    *                   class="Toys"
    * @return
    */
    private Set toys;



Likewise, within Toys, there is a many-to-one relationship, so the object Toys has a consumer. Here is the code snippit of the class definition of Toys:

Code:
   /**
    * @hibernate.many-to-one column="CONSUMER_ID"
    *                      class="Consumer"
    * @return
    */
   private Consumer consumer;


In my sample code, I try to add a toy to the set and my program crashes:

Code:
     Session s =  HibernateUtil.currentSession();
     Transaction tx = s.beginTransaction();

     Toys t = new Toys();
     ...
     t.setConsumer(consumer);
     consumer.getToys.Add(t);

     session.save(t);
     session.save(consumer);
     tx.commit();

     Hibernate.closeSession()



My program crashes at the "consumer.getToys.Add(t)" statement, and I'm at a lost of why this is happening. I am following directly a tutorial available online. Plus, the code above is within a try/catch block, and I did close both the session and transaction, which I read is a common reason for the "Warning: afterTransactionCompletion() never called."

I did not include the mapping files or hibernate.properties file because I am able to connect to the database, etc.

Specifically, here is the error I receive:

Code:
    [junit] Jan 20, 2005 10:42:31 PM net.sf.hibernate.impl.SessionImpl finalize
    [junit] WARNING: afterTransactionCompletion() was never called



I appreciate any feedback, it will be much appreciated. Thanks in advance for taking the time to read this post.

Thanks.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.