title: Hibernate ManyToMany and SINGLE_TABLE inheritance?
body: <p>please tell me what I'm doing wrong?</p>
  
  <p>I want to make ManyToMany relationship ratio in one table. Is this possible?</p>
  
  <pre><code>@Entity
  @Table(name = "external_offer")
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "offer_type", discriminatorType = DiscriminatorType.STRING)
  public abstract class ExternalOffer
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long id;
  
      ......
  </code></pre>
  
  <p>K-Entity</p>
  
  <pre><code>@Entity
  @Table(name = "k")
  public class K
  {
      @Id
      @Column(name = "id", nullable = false, updatable = false)
      private long id;
  
      @ManyToMany(fetch = FetchType.EAGER)
      @JoinTable(
          name = "K2GlobalOffer",
          joinColumns = @JoinColumn(
              name = "k_id", referencedColumnName = "id"),
          inverseJoinColumns = @JoinColumn(
              name = "global_offer_id", referencedColumnName = "id"))
      private List&lt;GlobalExternalOffer&gt; globalExternalOffers;
  </code></pre>
  
  <p>EOffer-Entity</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("GLOBAL")
  public class GlobalExternalOffer extends ExternalOffer
  {
  
      @ManyToMany(mappedBy = "globalExternalOffers", fetch = FetchType.EAGER)
      private List&lt;K&gt; kRef;
  </code></pre>
  
  <p>I receive here error. Do not understand why. This error I get only when there is ManyToMany. OneToMany relationship - works without problems.</p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:970)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:895)
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698)
      ... 75 common frames omitted
  Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112)
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
      at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:128)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:300)
      at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:460)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
      ... 82 common frames omitted
  Caused by: java.lang.ClassCastException: org.hibernate.type.BagType cannot be cast to org.hibernate.type.EntityType
      at org.hibernate.persister.entity.AbstractPropertyMapping.addPropertyPath(AbstractPropertyMapping.java:208)
      at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:395)
      at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:2300)
      at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:2347)
      at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3906)
      at org.hibernate.persister.entity.SingleTableEntityPersister.&lt;init&gt;(SingleTableEntityPersister.java:437)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
      ... 87 common frames omitted
  </code></pre>
  
  <p>Thanks for the help.</p>