views:

72

answers:

1

Hi,

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

+1  A: 

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
works great, thank you, i've came across the @CollectionOfElements annotation, but didn't know how to configure it. Anyway, thanks
Jan
@Jan - if this answer worked for you, mark it as accepted (the tick below the vote counter)
Bozho
@Jan: my pleasure... the hibernate mapping reference documentation can be a tough reading@Bozho: Thx ;-)
Thierry

related questions