2

I have this entity that i need to join with another unrelated entity, this is why I am using a native query.

@Entity
@Table(name = "surveillance_questionnaires")
@Setter @Getter
public class SurveillanceQuestionnaire {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "surveillance_questionnaires_sequence")
    @SequenceGenerator(name = "surveillance_questionnaires_sequence", allocationSize = 5)
    private Integer id;

    @ElementCollection
    @Fetch(FetchMode.JOIN)
    @CollectionTable(name = "surveillance_questionnaires_years", 
          joinColumns = @JoinColumn(name = "id", referencedColumnName = "id"))
    @Column(name = "year")
    private List<String> years;

    ...
}

Is there any way to fetch the SurveillanceQuestionnaire entity with its ElementCollection (years) using native query?

T. Aris
  • 31
  • 1
  • 5

0 Answers0