0

I' ve got 2 tables... Challenge and ChallengeYear, ChallengeYear is only to create a list of years in challenge.

I only want to make Challenge an entity, containing a list of List years. Is this possible?

I've looked in to @SecondaryTable together with @JoinColumn and @OneToMany, but neither of those can do the trick, or i am overlooking something.

Can someone help me?

Greetings, Jan

Jan
  • 3
  • 1
  • and how do you expect these to be persisted in the database? What does ChallangeYear contain? Is it only an integer containing the year, or there is more? – Bozho Mar 19 '10 at 09:47
  • it should be persisted like a @OneToMany(CascadeType.ALL, FetchType.EAGER) ChallengeYear contains a FK constraint to the Challenge and then a column year. So that it's possible to add several years to a challenge – Jan Mar 19 '10 at 10:02

1 Answers1

1

What is Year in your model, is it an Integer ?

if yes, you may annotate your Challenge.getYears method with @CollectionOfElements

like:

  @CollectionOfElements
  @JoinTable(
    table=@Table(name="ChallengeYear"),
    joinColumns = @JoinColumn(name="challengeId")
  )
  @Column(name="year", nullable=false)
  List<Integer> getYears() {
    ...
Thierry
  • 5,270
  • 33
  • 39
  • works great, thank you, i've came across the @CollectionOfElements annotation, but didn't know how to configure it. Anyway, thanks – Jan Mar 19 '10 at 11:00
  • @Jan - if this answer worked for you, mark it as accepted (the tick below the vote counter) – Bozho Mar 19 '10 at 12:10
  • @Jan: my pleasure... the hibernate mapping reference documentation can be a tough reading @Bozho: Thx ;-) – Thierry Mar 19 '10 at 14:41