-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: ManyToMany not persisting detached with 3.2.1 works in 3.2.0
PostPosted: Tue Dec 05, 2006 8:20 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
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;


Last edited by youngm77 on Wed Dec 06, 2006 2:13 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 12:45 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
bump


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 2:12 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
After a little further investigation it appears to only happen when animal is detached.

So Here is some actual code that duplicates the problem. If I comment out the SerializationUtils.clone then everything works fine. In addition if I downgrade to 3.2.0 everything works fine. Also note that the animal name is updated but the collection is not so it is not a problem of the session not being flushed or something.

Mike

Code:
        //Start Transaction
   Animal animal = entityManager.find(Animal.class, 21l);
   animal = (Animal)SerializationUtils.clone(animal);
       List<Country> countries = new ArrayList<Country>();
       countries.add(countryService.findAllCountries().get(2));
       animal.setCountries(countries);
       animal.setName("AaaCountry1");
       entityManager.merge(animal);
        //Committ Transaction


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 12:14 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
Ok, I guess I'll try filing a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 12:45 pm 
Regular
Regular

Joined: Thu Aug 26, 2004 9:23 pm
Posts: 71
http://opensource.atlassian.com/project ... e/HHH-2292


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 8:01 pm 
Newbie

Joined: Tue Mar 01, 2005 6:58 pm
Posts: 7
We're seeing the exact same problem. Is anything being done about this?


Top
 Profile  
 
 Post subject: only issue with merge, save-update works fine
PostPosted: Mon Oct 29, 2007 4:30 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
any work around for this?

_________________
-shailesh


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.