title: Multiple representations of the same entity are being merged Error
body: <p>I have been looking in many post here but still cant solve this. some say you need to remove CascadeType.MERGE but it didn't fix my error. my app is Spring-boot app, using hibernate &amp; MySQL db as a data source, my code:</p>
  
  <p>MySQL script:</p>
  
  <pre><code>DROP SCHEMA IF EXISTS `couponsystem`;
  
  CREATE SCHEMA `couponsystem`;
  
  use `couponsystem`;
  
  
  
  DROP TABLE IF EXISTS `company`;
  
  CREATE TABLE `company` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(20) NOT NULL UNIQUE,
    `password` varchar(20) NOT NULL,
    `email` varchar(20) DEFAULT NULL,
    PRIMARY KEY (`id`)
  )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
  
  
  DROP TABLE IF EXISTS `coupon`;
  
  CREATE TABLE `coupon` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(20) NOT NULL UNIQUE,
    `start_date` datetime DEFAULT NULL,
    `end_date` datetime DEFAULT NULL,
    `amount` int DEFAULT NULL,
    `type` varchar(15) DEFAULT NULL,
    `message` varchar(50) DEFAULT NULL,
    `price` float DEFAULT NULL,
    `company_id` int(11),
    PRIMARY KEY (`id`),
    KEY `FK_company_id` (`company_id`),
    CONSTRAINT `FK_company_id` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
  
  DROP TABLE IF EXISTS `customer`;
  
  CREATE TABLE `customer` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(20) NOT NULL UNIQUE,
    `password` varchar(20) NOT NULL,
    PRIMARY KEY (`id`)
  )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
  
  
  CREATE TABLE `customer_coupon`(
  
  `customer_id` int(11) NOT NULL,
  `coupon_id` int(11) NOT NULL,
  PRIMARY KEY (`customer_id`,`coupon_id`),
  KEY `fk_customer_coupon_idx` (`customer_id`),
  CONSTRAINT `FK_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_coupon_id` FOREIGN KEY (`coupon_id`) REFERENCES `coupon` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  
  
  )ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
  SET FOREIGN_KEY_CHECKS = 1;
  </code></pre>
  
  <p>Customer:</p>
  
  <pre><code>@Entity
  @Table(name = "customer")
  public class Customer {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private int id;
  
      ....
  
      @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.DETACH, CascadeType.REFRESH,
              CascadeType.MERGE })
      @JoinTable(name = "customer_coupon", joinColumns = @JoinColumn(name = "customer_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "coupon_id", referencedColumnName = "id"))
      private List&lt;Coupon&gt; coupons;
  </code></pre>
  
  <p>Coupon:</p>
  
  <pre><code>@Entity
  @Table(name = "coupon")
  public class Coupon {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private int id;
  
      ......
  
      @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.DETACH, CascadeType.REFRESH,
              CascadeType.MERGE })
      @JoinColumn(name = "company_id")
      private Company company;
  
      @ManyToMany(mappedBy = "coupons")
      private List&lt;Customer&gt; customers;
  </code></pre>
  
  <p>CustomerController:</p>
  
  <pre><code>@RequestMapping(value = "/purchaseCoupon")
      public ResponseEntity&lt;CouponSystemResponse&gt; purchaseCoupon(@RequestParam(value = "id") int id) {
              Coupon coupon = couponService.getCoupon(id);
              getEntity().getCoupons().add(coupon); --&gt;getEntity() gets the customer
              customerService.updateCustomer(getEntity());
  </code></pre>
  
  <p>CustomerService:</p>
  
  <pre><code>@Service
  public class CustomerService {
  
      @Autowired
      CustomerRepository customerRepo;
  
      .....
  
      public void updateCustomer(Customer customer) {
          customerRepo.save(customer);
      }
  </code></pre>
  
  <p>Every time I try to add a coupon to a customer I get this annoying error:</p>
  
  <pre><code>Multiple representations of the same entity [com.orel.couponsystem.entity.Coupon#2] are being merged. Managed: [Coupon [id=2, title=test[X][Y]2, startDate=2014-02-14 00:00:00.0, endDate=2018-02-14 00:00:00.0, amount=5, type=SPORTS, message=test, price=12.0]]; Detached: [Coupon [id=2, title=test[X][Y]2, startDate=2014-02-14 00:00:00.0, endDate=2018-02-14 00:00:00.0, amount=5, type=SPORTS, message=test, price=12.0]]; nested exception is java.lang.IllegalStateException: Multiple representations of the same entity [com.orel.couponsystem.entity.Coupon#2] are being merged. Managed: [Coupon [id=2, title=test[X][Y]2, startDate=2014-02-14 00:00:00.0, endDate=2018-02-14 00:00:00.0, amount=5, type=SPORTS, message=test, price=12.0]]; Detached: [Coupon [id=2, title=test[X][Y]2, startDate=2014-02-14 00:00:00.0, endDate=2018-02-14 00:00:00.0, amount=5, type=SPORTS, message=test, price=12.0]]
  </code></pre>
  
  <p>what cause this error to appear? how can it be fixed? as I say i tried to remove CascadeType.MERGE with no luck, saw something about equals method but couldn't really understand it, appreciate any help guys!</p>