title: I'm trying to establish many-to-many connections in the database. Because logically types and languages can have multiple books and vice versa
body: <pre><code> import lombok.Data;
  
   import javax.persistence.*;
   import java.util.List;
   import java.util.Objects;
   import java.util.Optional;
   import java.util.Set;
  
  
   @Entity
   @Data
   @Table(name = &quot;books&quot;)
  public class Book {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String name;
  private String publisher;
  private String author;
  private String aboutBook;
  private String fragment;
  private int date;
  private int volume;
  private int quantity;
  private int price;
  private int discount;
  private Boolean bestseller;
  private String bookLink;//s3
  
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = &quot;users_books&quot;,
          joinColumns = @JoinColumn(name = &quot;book_id&quot;),
          inverseJoinColumns = @JoinColumn(name = &quot;user_id&quot;))
  private List&lt;User&gt; users;
  
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = &quot;books_genres&quot;,
          joinColumns = @JoinColumn(name = &quot;book_id&quot;),
          inverseJoinColumns = @JoinColumn(referencedColumnName = &quot;genre_id&quot;))
  private Set&lt;Genre&gt; genres;
  
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = &quot;books_languages&quot;,
          joinColumns = @JoinColumn(name = &quot;book_id&quot;),
          inverseJoinColumns = @JoinColumn(referencedColumnName = &quot;language_id&quot;))
  private Set&lt;Language&gt; languages;
  
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = &quot;books_types&quot;,
          joinColumns = @JoinColumn(name = &quot;book_id&quot;),
          inverseJoinColumns = @JoinColumn(referencedColumnName = &quot;type_id&quot;))
  private Set&lt;Type&gt; types;
  
  
  
  public Optional&lt;String&gt; getBookLink() {
      return Optional.ofNullable(bookLink);
  }
  
  public void setBookLink(String bookLink) {
      this.bookLink = bookLink;
  }
  
  
  @Override
  public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Book book = (Book) o;
      return date == book.date &amp;&amp;
              volume == book.volume &amp;&amp;
              quantity == book.quantity &amp;&amp;
              price == book.price &amp;&amp;
              discount == book.discount &amp;&amp;
              id.equals(book.id) &amp;&amp;
              name.equals(book.name) &amp;&amp;
              publisher.equals(book.publisher) &amp;&amp;
              author.equals(book.author) &amp;&amp;
              aboutBook.equals(book.aboutBook) &amp;&amp;
              fragment.equals(book.fragment) &amp;&amp;
              bestseller.equals(book.bestseller)
              &amp;&amp; users.equals(book.users);
  }
  
  @Override
  public int hashCode() {
      return Objects.hash(id, name, publisher, author, aboutBook, fragment, date, volume, quantity, price, discount, bestseller, users);
  }
  
   } 
  </code></pre>
  <hr />
  <pre><code>@Entity
  @Data
  @Table(name = &quot;genres&quot;)
  public class Genre {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  private String name;
  
  @ManyToMany(mappedBy = &quot;genres&quot;)
  private List&lt;Book&gt; books;
  }
  </code></pre>
  <hr />
  <pre><code> @Entity
   @Data
   @Table(name = &quot;languages&quot;)
   public class Language {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;
  
   private String name;
  
   @ManyToMany(mappedBy = &quot;languages&quot;)
   private List&lt;Book&gt; books;
   }
  </code></pre>
  <hr />
  <pre><code>@Entity
  @Data
  @Table(name = &quot;types&quot;)
  public class Type {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  private String name;
  @ManyToMany(mappedBy = &quot;types&quot;)
  private List&lt;Book&gt; books;
  
  }
  </code></pre>
  <hr />
  <pre><code>@Entity
  @Data
  @Table(name = &quot;users&quot;)
  public class User {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = &quot;id&quot;)
  private Long id;
  
  @Column(name = &quot;username&quot;)
  private String username;
  @Column(name = &quot;last_name&quot;)
  private String lastName;
  
  @Column(name = &quot;password&quot;)
  private String password;
  
  @Column(name = &quot;email&quot;)
  private String email;
  
  @Column(name = &quot;number_of_phone&quot;)
  private Long number;
  
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = &quot;users_roles&quot;,
          joinColumns = @JoinColumn(name = &quot;user_id&quot;),
          inverseJoinColumns = @JoinColumn(name = &quot;role_id&quot;))
  private Set&lt;Role&gt; roles;
  
  public Set&lt;Role&gt; getRoles() {
      return roles;
  }
  
  public void setRoles(Set&lt;Role&gt; roles) {
      this.roles = roles;
  }
  
  }
  </code></pre>
  <hr />
  <p>but I get this error</p>
  <hr />
  <pre><code>   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
    'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.cfg.RecoverableException: Unable to find column with logical name: type_id in org.hibernate.mapping.Table(types) and its related supertables and secondary tables
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.16.jar:5.3.16]
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.16.jar:5.3.16]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar:5.3.16]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) [spring-boot-2.6.4.jar:2.6.4]
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) [spring-boot-2.6.4.jar:2.6.4]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-2.6.4.jar:2.6.4]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) [spring-boot-2.6.4.jar:2.6.4]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) [spring-boot-2.6.4.jar:2.6.4]
  at com.ebook.EBookApplication.main(EBookApplication.java:10) [classes/:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_311]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_311]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_311]
  at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_311]
  at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.6.4.jar:2.6.4]
  Caused by: org.hibernate.cfg.RecoverableException: Unable to find column with logical name: type_id in org.hibernate.mapping.Table(types) and its related supertables and secondary tables
  at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:844) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:126) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.annotations.CollectionBinder.bindManytoManyInverseFk(CollectionBinder.java:1802) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1679) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:874) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:799) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:53) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1653) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1629) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:295) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.16.jar:5.3.16]
  at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.16.jar:5.3.16]
  at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.16.jar:5.3.16]
  at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.16.jar:5.3.16]
  at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.16.jar:5.3.16]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.16.jar:5.3.16]
  ... 21 common frames omitted
  Caused by: org.hibernate.MappingException: Unable to find column with logical name: type_id in org.hibernate.mapping.Table(types) and its related supertables and secondary tables
  at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:839) ~[hibernate-core-5.6.5.Final.jar:5.6.5.Final]
  ... 39 common frames omitted`
  </code></pre>
  <hr />