Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Odd problem with JPA / Hibernate Entitymanager and Spring 2.0

  1. #11
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you modifying an object which has a bi-directional relationship, you do have to update both ends if you are adding or removing an item.

    Code:
    category.getItems().add(item); // The category now "knows" about the relationship
    item.getCategories().add(category); // The item now "knows" about the relationship
    
    session.update(item); // No effect, nothing will be saved!
    session.update(category); // The relationship will be saved
    http://www.hibernate.org/hib_docs/re...-bidirectional

  2. #12
    Join Date
    Jan 2007
    Posts
    9

    Default

    asbjorjo,

    Have you found a solution for your problem yet? I'm facing the same problem as you do. Even if I updated the relationships on both ends, merge doesn't seem to work on a detached entity.

  3. #13
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Could you explain more about your problem? Is it the same thing e.g. working with many-to-many relationships? Does it work if the entity isn't detached e.g. can you replicate this in a unit test?

  4. #14
    Join Date
    Jan 2007
    Posts
    9

    Default

    karldmoore,

    I found out that there was no transaction available during my update for the many-to-many relationships. This is a separate Spring issue that I filed here

    http://forum.springframework.org/showthread.php?t=35562

    Once I figured out the transaction problem, I will attempt the many-to-many relationship again and post my finding.

  5. #15
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Ok, if there is a no transaction then you might have problem here. I'll try and have a look at the other thread later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •