Cached entity with mutable=false generates duplicate entry error
An entity, used caching. Because of caching, a readonly error was got, then `mutable =false` added.

        @org.hibernate.annotations.Entity(mutable=false)
        @javax.persistence.Entity
        @Table(name = "ProductCategory")
        @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
        public class ProductCategory implements Serializable  {


	         @ManyToOne(fetch=FetchType.EAGER)
 	         private ProductCategory parentProductCategory;
	
	
	         @OneToMany(fetch=FetchType.LAZY,orphanRemoval=true, mappedBy="parentProductCategory", cascade ={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH, CascadeType.REMOVE})
	         @OnDelete(action = OnDeleteAction.CASCADE)
	         @org.hibernate.annotations.BatchSize(size=0)
 	         private List<ProductCategory> childProductCategorys  = new ArrayList<ProductCategory>();

    }

In a controller, i try to generate a child and add it to the parent


        productCategory=new ProductCategory();

Above line runs as a commandbutton's action, then a dialog appears, a button in dialog make the below code to run.
...

    productCategory.setParentProductCategory(this.selectedProductCategory);
        productCategory=productCategoryService.save(productCategory);
        this.selectedProductCategory.getChildProductCategorys().add(productCategory);
        productCategoryService.save(selectedProductCategory);


When i commented cache and mutable lines, it works as i expected. But now throws duplicate entry exception at the last line. Save method, calls `entitymanager.merge`.
Cached entity with mutable=false generates duplicate entry error
===

An entity, used caching. Because of caching, a readonly error was got, then `mutable =false` added.

        @org.hibernate.annotations.Entity(mutable=false)
        @javax.persistence.Entity
        @Table(name = "ProductCategory")
        @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
        public class ProductCategory implements Serializable  {


	         @ManyToOne(fetch=FetchType.EAGER)
 	         private ProductCategory parentProductCategory;
	
	
	         @OneToMany(fetch=FetchType.LAZY,orphanRemoval=true, mappedBy="parentProductCategory", cascade ={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH, CascadeType.REMOVE})
	         @OnDelete(action = OnDeleteAction.CASCADE)
	         @org.hibernate.annotations.BatchSize(size=0)
 	         private List<ProductCategory> childProductCategorys  = new ArrayList<ProductCategory>();

    }

In a controller, i try to generate a child and add it to the parent


        productCategory=new ProductCategory();

Above line runs as a commandbutton's action, then a dialog appears, a button in dialog make the below code to run.
...

    productCategory.setParentProductCategory(this.selectedProductCategory);
        productCategory=productCategoryService.save(productCategory);
        this.selectedProductCategory.getChildProductCategorys().add(productCategory);
        productCategoryService.save(selectedProductCategory);


When i commented cache and mutable lines, it works as i expected. But now throws duplicate entry exception at the last line. Save method, calls `entitymanager.merge`.