[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2292) Regression between 3.2.0 and 3.2.1. Merge detached instance fails to persist ManyToMany relationship

Steve Ebersole (JIRA) noreply at atlassian.com
Tue Jan 9 09:11:44 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2292?page=comments#action_25764 ] 

Steve Ebersole commented on HHH-2292:
-------------------------------------

ugh!  Somehow when the collection is a "bare reference" the original detached collection collection is being mutated in addition to the merged/persistent collection.  I need to find the cause of that, which would probably be the cause.  From what I can tell, that is the reson the in memory state is fine after the merge but the merged changes are not persisteted (because after the in memory merge the two collection look the same).

> Regression between 3.2.0 and 3.2.1.  Merge detached instance fails to persist ManyToMany relationship
> -----------------------------------------------------------------------------------------------------
>
>          Key: HHH-2292
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2292
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.2.1
>     Reporter: Mike Youngstrom
>     Priority: Critical

>
>
> I have a ManyToMany relationship.  If I attempt to merge a detached instance of the owning side of that relationship the changes to the ManyToMany fail to be persisted.  The merge propertly takes place and the persistence context is correctly updated but the SQL commands to update the database are not sent when the session is flushed.  I'm using HA 3.2.0 and EM 3.2.0.  If I replace the core 3.2.1 jar with 3.2.0 the operation works perfectly.  If I attempt the operation on an attached instance the operation works perfectly.  it only doesn't work with 3.2.1 with a detached instance.  Here are the example entities and example code to duplicate the problem.
> --------------Animal.java---------------
> @Entity
> @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
> @SuppressWarnings("serial")
> public class Animal implements Serializable {
>    @Id @GeneratedValue
>    private Long id;
>     private String name;
>     @ManyToOne
>     @Basic(fetch=FetchType.LAZY)
>     private Classification classification;
>     @ManyToMany
>     @JoinTable(name="ANIMAL_COUNTRY",
>           joinColumns=@JoinColumn(name="ANIMAL_ID"),
>           inverseJoinColumns=@JoinColumn(name="COUNTRY_ID"))
>     @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
>     @Basic(fetch=FetchType.LAZY)
>     private List<Country> countries;
>     @SuppressWarnings("unused")
>    @Version
>     private Long version;
>     
>     /** SNIP Getters and Setters **/
> }
> ------------Country.java-----------------
> @Entity
> @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
> @SuppressWarnings("serial")
> public class Country implements Serializable {
>    @Id @GeneratedValue @Column(updatable=false)
>    private Long id; //NOPMD - wheelermm
>    @Column(unique=true, nullable=false)
>     public String name;
>     @Basic(fetch=FetchType.LAZY)
>     @ManyToMany(mappedBy="countries")
>     @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
>     public List<Animal> animals;
> }
> -----------Example code to duplicate problem----------------
> //Start Transaction
> Animal animal = entityManager.find(Animal.class, 21l);
> animal = (Animal)SerializationUtils.clone(animal); // Detach the animal
> List<Country> countries = new ArrayList<Country>();
> countries.add(countryService.findAllCountries().get(2));
> animal.setCountries(countries);
> animal.setClassification(entityManager.find(Classification.class, 1l);
> animal.setName("Modified Animal");
> entityManager.merge(animal);
> //Commit Transaction 
> When the example code above runs both the animal.name and animal.classification are persisted but the change of country is not persisted.  the object returned from entityManger.merge() contains the correct country but the db is never updated.  if I comment out the clone() (making it not detached) everything works fine.  If I downgrade to 3.2.0 everything works fine.
> Mike
> Forum post: http://forum.hibernate.org/viewtopic.php?t=968226

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list