I'm having a problem with ManyToMany merging with 3.2.1 that worked just fine in 3.2.0. I can literally switch out the 3.2.1 jar with 3.2.0 and see it work.
I have a many to many relationship between Animals and Countries. Animals is the owning side. If I modify the entries in Animals.countries and do a merge the countries are correctly merged and an animal with the correct countries is returned however no db modification sql is ever issued. Other modifications to the Animal entity are correctly persisted including a ManyToOne I have with on other entities but the changes to the ManyToMany are not persisted to the database. Any ideas? Below are the mappings.
Mike
Example.java //Some pseudo code that is giving the problem
Code:
Animal animal = getADetachedAnimal();
List<Country> countries = new ArrayList<Country>();
countries.add(getACountry());
animal.setCountries(countries);
begin a transaction
em.merge(animal);
end a transaction
Animal.java
Code:
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@NamedQueries({
@NamedQuery(name=Animal.QUERY_GET_ALL_ANIMALS_AS_SELECT_ITEMS, query="select new javax.faces.model.SelectItem(a, a.name) from Animal a")
})
@SuppressWarnings("serial")
public class Animal implements Serializable {
public static final String QUERY_GET_ALL_ANIMALS_AS_SELECT_ITEMS = "getAllAnimalsAsSelectItems";
@Id @GeneratedValue
private Long id;
private String name;
@Enumerated(EnumType.STRING)
private Gender gender;
@Column(length=4000)
private String description;
private String imageUrl;
private double price;
private Date dateOfBirth;
@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;
Country.java
Code:
@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;