title: Unidirectional OneToMany Hibernate without an extra join table
body: <p>The setup is this: My Application has many Events that could happen. An Event is just a few added fields and an EventCode that has some information. Basically Events is a join table itself with a few pieces of information added on.</p>
  
  <p>I want to avoid creating a table of ApplicationId and EventId. Just does not seem needed</p>
  
  <p>The error I am getting </p>
  
  <pre><code>Caused by: org.hibernate.MappingException: Foreign key (FK_157jxjblselu4urv8c0kqee6l:ApplicationEvent [applicationEvents_id])) must have same number of columns as the referenced primary key (ApplicationEvent [Application_id,applicationEvents_id])
  </code></pre>
  
  <p>Application (A lot removed but this is where the issue is)</p>
  
  <pre><code>@Entity
  @Table
  public class Application {
      //Lots of other stuff
      private Set&lt;ApplicationEvent&gt; applicationEvents = new LinkedHashSet&lt;ApplicationEvent&gt;();
  
      @OneToMany
      @JoinTable(name="ApplicationEvent")
      public Set&lt;ApplicationEvent&gt; getApplicationEvents() {
          return applicationEvents;
      }
  
      public void setApplicationEvents(Set&lt;ApplicationEvent&gt; applicationEvents) {
          this.applicationEvents = applicationEvents;
      }
  }
  </code></pre>
  
  <p>The Event</p>
  
  <pre><code>@Entity
  @Table
  public class ApplicationEvent {
  
      private Long id;
      private Long applicationId;
      private EventCode eventCode;
      private Boolean acknowledge;
      private int sequence;
  
  
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      @Column
      public Long getApplicationId() {
          return applicationId;
      }
  
      public void setApplicationId(Long applicationId) {
          this.applicationId = applicationId;
      }
  
      @OneToOne
      @JoinColumn(name="EventCodeId")
      public EventCode getEventCode() {
          return eventCode;
      }
  
      public void setEventCode(EventCode eventCode) {
          this.eventCode = eventCode;
      }
  
      @Column
      public Boolean getAcknowledge() {
          return acknowledge;
      }
  
      public void setAcknowledge(Boolean acknowledge) {
          this.acknowledge = acknowledge;
      }
  
      @Column
      public int getSequence() {
          return sequence;
      }
  
      public void setSequence(int sequence) {
          this.sequence = sequence;
      }
  
  //Some overriden methods
  }
  </code></pre>