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.