title: Association not working in Spring Boot
body: <p>I am a newbie in Spring but learned quite a lot over the last weeks. I have a Spring Boot project which works fine for simple resources, but once I do associations, some things don't work as expected. </p>
  
  <p>My simplified application has the Resources Event and Invitation, where an event can have multiple invitations.</p>
  
  <p>Now I have two problems:</p>
  
  <ol>
  <li><p>When I do a call on the API for events, I get the events, but there are no invitations in the output. I see in my MySqlLogs, that there is a query querying for invitations and when I copy and past this query into my mysql client, I get a lot of results</p></li>
  <li><p>There is no JOIN between event and invitations. There is one event query, and then one query for invitations for each event in the result. But I would expect a JOIN here in order to have just one query. I tried these annoatations</p>
  
  <p>@OneToMany(mappedBy="event", fetch=FetchType.EAGER)
  @Fetch(FetchMode.JOIN)</p></li>
  </ol>
  
  <p>but they didn't make any difference. Does anyone sees why there are no invitations in my API output and why there are single queries instead of a JOIN?</p>
  
  <p>Thanks a lot for your help.</p>
  
  <p>The example output I see is:</p>
  
  <pre><code>{
      content: [
        {
          id: 374223,
          start: "2016-12-12 17:30",
          end: "2016-12-12 20:00",
          name: "Hallentraining",
          slug: "hallentraining-501-2016-12-12",
          invitations: [
              {
                  id: 0,
                  message: null,
                  invitationState: 1,
                  memberId: null,
                  version: 0
              }
          ],
          version: 0
         }
       ],
      last: true,
      totalPages: 1,
      totalElements: 1,
      first: true,
      sort: null,
      numberOfElements: 1,
      size: 20,
      number: 0
  }
  </code></pre>
  
  <p>Event Class</p>
  
  <pre><code>@Entity
  @Component
  @Table(name="event")
  public class Event implements MyEntity {
  
      @Id
      @Column(name="id")
      @GeneratedValue
      private Long id;
  
      private String name;
  
      private String slug;
  
      @Column(name="start")
      @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
      @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
      private DateTime start;
  
      @Column(name="end")
      @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
      @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
      private DateTime end;
  
      @OneToMany(mappedBy="event", fetch=FetchType.EAGER)
      @Fetch(FetchMode.JOIN)
      private Set&lt;Invitation&gt; invitations = new HashSet&lt;&gt;();
  
  // getters and setters 
  }
  </code></pre>
  
  <p>Invitation Class</p>
  
  <pre><code>@Entity
  @Component
  @Table(name="invitation")
  public class Invitation implements MyEntity {
  
      @Id
      @Column(name="id")
      @GeneratedValue
      private Long id;
  
  
  
      private String message;
  
      @Column(name="invitation_state")
      private Integer invitationState;
  
      @Column(name="member_id")
      private Integer memberId;
  
      @ManyToOne
      @JoinColumn(name="event_id", nullable=false)
      private Event event;
  
      // getters and setters 
  }
  </code></pre>
  
  <p>EventRepository:</p>
  
  <pre><code>public interface  EventRepository extends JpaRepository&lt;Event, Long&gt;, JpaSpecificationExecutor {
  
  }
  </code></pre>
  
  <p>EventController:</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/event" , produces="application/json")
  public class EventController {
  
      @Autowired
      private EventRepository repo;
  
      @Autowired
      private EventService eventService;
  
      @RequestMapping(method = RequestMethod.GET)
  
       public Iterable&lt;Event&gt; event(Pageable pageable,
                                   String start ,
                                   String end ,
                                   String name) {
          EventSpecification spec = new EventSpecification(start, end, name );
  
          return repo.findAll( spec, pageable );
      }
  }
  </code></pre>
  
  <p>Extract of my build.gradle:</p>
  
  <pre><code>compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.3.6.RELEASE'
  compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.3.6.RELEASE'
  compile 'com.fasterxml.jackson.core:jackson-databind:2.5.0'
  compile 'mysql:mysql-connector-java:5.1.34'
  compile group: 'joda-time', name: 'joda-time', version: '2.9.5'
  compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-joda', version: '2.8.4'
  compile group: 'org.jadira.usertype', name: 'usertype.core', version: '3.2.0.GA'
  </code></pre>