[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2292?page=c...
]
Mike Youngstrom commented on HHH-2292:
--------------------------------------
One other note. It only seems to not work when a new Collection is created and set in the
detached entity. If the existing colleciton is modified:
animal.getCountries().clear();
animal.getCountries().addAll(countries)
then it works fine as well. However, in order to get that to work I had to make the many
to many fetch eager for Animal.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira