Hi,
Thanks for the help. But I am still facing some problem.
It gives me error. following is the stack trace

net.sf.hibernate.HibernateException: Another object was associated with this
id (the object with the given id was already loaded):
[presci.walnut.manytomany.Work#0]
 at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1294)
 at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1218)
 at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:81)
 at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:238)
 at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:272)
 at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:306)
 at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
 at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:620)
 at presci.walnut.manytomany.AuthorWork.add(AuthorWork.java:55)
 at presci.walnut.manytomany.AuthorWork.main(AuthorWork.java:81)

when I run the following code.

  Session session = null;
  Transaction tx = null;
  try {
   session = sessions.openSession();
   tx = session.beginTransaction();

   LinkedHashSet _work = new LinkedHashSet();
   _work.add(new Work("Title 1"));
    _work.add(new Work("Title 2"));
   _work.add(new Work("Title 3"));
   _work.add(new Work("Title 4"));
   _work.add(new Work("Title 5"));
   _work.add(new Work("Title 6"));
   _work.add(new Work("Title 7"));
   _work.add(new Work("Title 8"));

   Author author = new Author("Prasad", _work);

   session.save(author);

   session.flush();
   tx.commit();

  } catch (Exception ex) {
   ex.printStackTrace();
   try {
    if (tx != null)
     tx.rollback();
   } catch (Exception iex) {
    System.err.println("Err rolling back the transaction");
   }
  } finally {
   try {
    if (session != null)
     session.close();
   } catch (Exception ex) {
    System.err.println("Error closing session");
   }

Thanks for the help
regards
prasad chandrasekaran

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Prasad Iyer" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Monday, August 11, 2003 4:02 PM
Subject: Re: [Hibernate] Hi (Problem with Many to Many relationship)


>
> where is your cascade="save-update"???!
>
>
>
> |---------+------------------------------------------->
> |         |           "Prasad Iyer"                   |
> |         |           <[EMAIL PROTECTED]>      |
> |         |           Sent by:                        |
> |         |           [EMAIL PROTECTED]|
> |         |           ceforge.net                     |
> |         |                                           |
> |         |                                           |
> |         |           11/08/03 08:29 PM               |
> |         |           Please respond to "Prasad Iyer" |
> |         |                                           |
> |---------+------------------------------------------->
>
>---------------------------------------------------------------------------
---------------------------------------------------|
>   |
|
>   |       To:       <[EMAIL PROTECTED]>
|
>   |       cc:
|
>   |       Subject:  Re: [Hibernate] Hi (Problem with Many to Many
relationship)                                                  |
>
>---------------------------------------------------------------------------
---------------------------------------------------|
>
>
>
>
> Hi again,
> It should be working. But it isn't working in my case :). I am sending my
> hibernating mapping with this email.
> The scenario is I have Author Bean which has one property type as Set
which
> holds Collection of the Title Bean. And in Title Bean I have property type
> Set which holds collection of Authors.
> I have this Author which has collection of five Title I need to add it to
> database.
> session.save(author). Only Author gets saved not the Title. If you have
any
> example or any site which explains this please let me know
> thanks
> regards
> prasad chandrasekaran
>
> <hibernate-mapping>
>     <class name="presci.walnut.manytomany.Author" table="author">
>         <id name="id">
>             <generator class="identity"/>
>         </id>
>
>         <property name="name"/>
>         <set name="work" table="author_work" inverse="true">
>          <key column="author_id"/>
>          <many-to-many class="presci.walnut.manytomany.Work"
> column="work_id"/>
>         </set>
>     </class>
>
>     <class name="presci.walnut.manytomany.Work" table="work">
>         <id name="id">
>             <generator class="identity"/>
>         </id>
>
>         <property name="title"/>
>         <set name="author" table="author_work" inverse="true">
>          <key column="work_id"/>
>          <many-to-many class="presci.walnut.manytomany.Author"
> column="author_id"/>
>         </set>
>     </class>
>
>     <class name="presci.walnut.manytomany.Author_Work"
table="author_work">
>      <composite-id>
>       <key-many-to-one class="presci.walnut.manytomany.Author"
> name="author"
> column="author_id"/>
>       <key-many-to-one class="presci.walnut.manytomany.Work" name="work"
> column="work_id"/>
>      </composite-id>
>     </class>
> </hibernate-mapping>
>
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: "Prasad Iyer" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Monday, August 11, 2003 3:42 PM
> Subject: Re: [Hibernate] Hi (Problem with Many to Many relationship)
>
>
> >
> > No, you shouldn't need to do anything special .... cascade semantics are
> > same as one-to-many.
> >
> >
> >
> >
> > |---------+------------------------------------------->
> > |         |           "Prasad Iyer"                   |
> > |         |           <[EMAIL PROTECTED]>      |
> > |         |           Sent by:                        |
> > |         |           [EMAIL PROTECTED]|
> > |         |           ceforge.net                     |
> > |         |                                           |
> > |         |                                           |
> > |         |           11/08/03 05:00 PM               |
> > |         |           Please respond to "Prasad Iyer" |
> > |         |                                           |
> > |---------+------------------------------------------->
> >
>
>---------------------------------------------------------------------------
>
> ---------------------------------------------------|
> >   |
> |
> >   |       To:       <[EMAIL PROTECTED]>
> |
> >   |       cc:
> |
> >   |       Subject:  [Hibernate] Hi (Problem with Many to Many
> relationship)                                                      |
> >
>
>---------------------------------------------------------------------------
> ---------------------------------------------------|
> >
> >
> >
> >
> > Hi,
> > Supponse I have a Author and Title table with many to many relationship.
> > The problem is if I have one Author with many titles. Do I have to
> > explicitly add Titles using session.save(title) to save the individual
> > titles for the author. I think hibernate should take care of it
> internally
> > like it does for many-to-many relationship.
> > Does anyone have example for many-to-many relationship.
> > This would help me a lot.
> > regards
> > prasad chandrasekaran
> >
> >
> >
> > **********************************************************************
> > Any personal or sensitive information contained in this email and
> > attachments must be handled in accordance with the Victorian Information
> > Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988
> > (Commonwealth), as applicable.
> >
> > This email, including all attachments, is confidential.  If you are not
> the
> > intended recipient, you must not disclose, distribute, copy or use the
> > information contained in this email or attachments.  Any confidentiality
> or
> > privilege is not waived or lost because this email has been sent to you
> in
> > error.  If you have received it in error, please let us know by reply
> > email, delete it from your system and destroy any copies.
> > **********************************************************************
> >
> >
> >
> >
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> hibernate-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>
>
>
>
> **********************************************************************
> Any personal or sensitive information contained in this email and
> attachments must be handled in accordance with the Victorian Information
> Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988
> (Commonwealth), as applicable.
>
> This email, including all attachments, is confidential.  If you are not
the
> intended recipient, you must not disclose, distribute, copy or use the
> information contained in this email or attachments.  Any confidentiality
or
> privilege is not waived or lost because this email has been sent to you in
> error.  If you have received it in error, please let us know by reply
> email, delete it from your system and destroy any copies.
> **********************************************************************
>
>
>
>



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to