0

I have got ManyToMany Relation Ship

@ManyToMany
@JoinTable(name = "competition_tag",
        joinColumns = @JoinColumn(name = "competition_id"),
        inverseJoinColumns = @JoinColumn(name = "tag_id"))
private Set<CompetitionTags> tags = new HashSet<>();


public void addTagToCompetition(CompetitionTags competitionTags) {
    this.tags.add(competitionTags);
    competitionTags.getCompetitions().add(this);
}

But when i use addTagToCompetition I getting NullPointerException. Can you please give me any advice/tip why this happen. I add whole object. If this will be needed , whole class is on : github link

Nowak Adam
  • 31
  • 1
  • 4
  • 2
    Check the stack trace where exactly the NPE happens. – Henry Oct 19 '20 at 11:05
  • competition.addTagToCompetition(competitionTag); – Nowak Adam Oct 19 '20 at 11:11
  • @Henry: NPE caused by `String str1 = null; String str2 = str1.toUpperCase();` is quite different from one caused with the ORM engine. I don't know what is the cause here, the point is I'd not close the question with a duplicate to THAT one UNTIL the OP provides the relevant code and what does the `competitionTags` input looks like. If you insist on the closing, I'd go for "needs more clarity". – Nikolas Charalambidis Oct 19 '20 at 11:11
  • if the NPE is ultimately in `competition.addTagToCompetition(competitionTag);` then `competition` is `null` at this point. – Henry Oct 19 '20 at 11:15

0 Answers0