title: Issue with Hibernate many to many mapping
body: <p>I have a hibernate + oracle program. In that, I have a many-to-many relationship between "Applications" and "IdentityProviders" table via the "ApplicationIdentityProviders" table. I am getting the following error while running the program:</p>
  
  <pre><code>Exception in thread "main" java.lang.RuntimeException: org.hibernate.MappingException: 
  Could not determine type for: String, at table: identity_providers, for columns: [org.hibernate.mapping.Column(issuer)]
  at com.oracle.hibernate.OCIAuthManager.setupTenant1Pdb1(OCIAuthManager.java:246)
  at com.oracle.hibernate.OCIAuthManager.main(OCIAuthManager.java:283)
  </code></pre>
  
  <p>I am unable to figure out why. Applications.java is <a href="https://pastebin.com/2wk4tKga" rel="nofollow noreferrer">here</a>. IdentityProviders.java is <a href="https://pastebin.com/B0ZxurSg" rel="nofollow noreferrer">here</a>. ApplicationIdentityProviders.java is <a href="https://pastebin.com/LCVVujrW" rel="nofollow noreferrer">here</a>. Main class is <a href="https://pastebin.com/93mi8q0j" rel="nofollow noreferrer">here</a>. Applications.hbm.xml is as follows:</p>
  
  <pre><code>&lt;?xml version = "1.0" encoding = "utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt; 
  
  &lt;hibernate-mapping&gt;
   &lt;class name = "Applications" table = "applications"&gt;
  
    &lt;meta attribute = "class-description"&gt;
       This class contains the applications details. 
    &lt;/meta&gt;
  
    &lt;id name = "application_id" type = "int" column = "application_id"&gt;
       &lt;generator class="native"/&gt;
    &lt;/id&gt;
  
    &lt;set name = "application_id_providers" cascade="save-update" table="application_identity_providers"&gt;
       &lt;key column = "application_id"/&gt;
       &lt;many-to-many column = "identity_provider_id" class="IdentityProviders"/&gt;
    &lt;/set&gt;
  
    &lt;property name = "application_name" column = "application_name" type = "string"/&gt;
    &lt;property name = "attr" column = "attr" type = "short"/&gt;
    &lt;property name = "salary" column = "salary" type = "int"/&gt;
  
   &lt;/class&gt;
  
   &lt;class name = "IdentityProviders" table = "identity_providers"&gt;
  
    &lt;meta attribute = "class-description"&gt;
       This class contains the identity providers' details. 
    &lt;/meta&gt;
  
    &lt;id name = "identity_provider_id" type = "int" column = "identity_provider_id"&gt;
       &lt;generator class="native"/&gt;
    &lt;/id&gt;
  
    &lt;property name = "attr" column = "attr" type = "short"/&gt;
    &lt;property name = "protocols" column = "protocols" type = "short"/&gt;
    &lt;property name = "issuer" column = "issuer" type = "String"/&gt;
    &lt;property name = "cert1" column = "cert1" type = "String"/&gt;
    &lt;property name = "cert2" column = "cert2" type = "String"/&gt;
    &lt;property name = "is_tenant_default" column = "is_tenant_default" type = "short"/&gt;
  
   &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>hibernate-1.cfg.xml is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
  
      &lt;property name="connection.url"&gt;jdbc:oracle:thin:@//localhost:1521/t1p1.oradev.oraclecorp.com&lt;/property&gt;
      &lt;property name="connection.username"&gt;username&lt;/property&gt;
      &lt;property name="connection.password"&gt;password&lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;oracle.jdbc.OracleDriver&lt;/property&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.Oracle12cDialect&lt;/property&gt;
  
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;property name="format_sql"&gt;true&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;mapping resource = "Applications.hbm.xml"/&gt;
  
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Where am I going wrong? Kindly help.</p>
  
  <p>Update 1: @Guillaume's answer worked. But I am now getting the following error: </p>
  
  <pre><code>Exception in thread "main" java.lang.RuntimeException:
  org.hibernate.MappingException: An association from the table 
  application_identity_providers refers to an unmapped class: 
  IdentityProviders at
  com.oracle.hibernate.OCIAuthManager.setupTenant1Pdb1(OCIAuthManager.java:246) 
  at com.oracle.hibernate.OCIAuthManager.main(OCIAuthManager.java:283)
  </code></pre>
  
  <p>Update 2: I resolved the error in update 1. Now I am getting the following error:
  ERROR: ORA-01400: cannot insert NULL into ("SYS"."APPLICATION_IDENTITY_PROVIDERS"."APPLICATION_IDENTITY_PROVIDER_ID")</p>
  
  <p>This error occurs in the intermediate table holding the primary keys of two other tables which have a many-to-many mapping. In ApplicationIdentityProviders.java, I have:</p>
  
  <pre><code>@Id
  @SequenceGenerator(name="seq",sequenceName="oracle_seq",allocationSize=1)        
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
  private int application_identity_provider_id;
  </code></pre>
  
  <p>When I run the program, the relevant output snippet is:
      Hibernate: </p>
  
  <pre><code>create table application_identity_providers (
  application_identity_provider_id number(10,0) not null,
  application_id number(10,0) not null,
  identity_provider_id number(10,0) not null,
  is_application_default number(5,0) not null,
  primary key (application_id, identity_provider_id)
  )
  </code></pre>
  
  <p>Where am I going wrong?</p>
  
  <p>Update 3: Given "application_name" in "applications" table, fetch entire content in "identity_providers" and "saml_identity_providers" tables. How to do it?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>Query query = entitymanager.createQuery("select a from Applications a join 
  fetch a.ApplicationIdentityProviders ap " +
  "join fetch ap.IdentityProviders ip where a.application_name = 
  'newApplicationName'");
  </code></pre>
  
  <p>It is giving me this error:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean 
  with name 'applicationsRepository' defined in file 
  [D:\filepath\ApplicationsRepository.class]: Bean instantiation via 
  constructor failed; nested exception is 
  org.springframework.beans.BeanInstantiationException: Failed to instantiate 
  [ApplicationsRepository]: Constructor threw exception; nested exception is 
  java.lang.IllegalArgumentException: org.hibernate.QueryException: could not 
  resolve property: ApplicationIdentityProviders of: Applications [select a 
  from com.package.entities.Applications a join fetch 
  a.ApplicationIdentityProviders ap join fetch 
  ap.IdentityProviders ip where a.application_name = 'newApplicationName']
  </code></pre>