mardi 24 février 2015

Incomplete @JoinColumns



I'm having a problem with JPA when trying to create some models to my database.


I have these three classes (I'll just put part of the code here):


GuideVersionLang



@Entity
public class GuideVersionLang implements LangItem {
...
@ManyToOne
@JoinColumns({
@JoinColumn(name="GUIDE_VERSION_NUMBER", referencedColumnName="VERSION_NUMBER"),
@JoinColumn(name="GUIDE_ID", referencedColumnName="GUIDE_ID")
})
@JsonIgnore
private GuideVersion guideVersion;
...
}


GuideVersion



@Entity
@IdClass(value=GuideVersionKey.class)
public class GuideVersion {
...
@OneToMany(mappedBy="guideVersion", orphanRemoval=true, cascade=CascadeType.PERSIST)
private LangsCollection<GuideVersionLang> guideVersionLangs;

@Id
@ManyToOne
@JoinColumn(nullable = false, name="GUIDE_ID")
@JsonIgnore
private Guides guide;

@Id
@Column(name = "VERSION_NUMBER")
private long versionNumber;
...
}


And GuideVersionKey



@Embeddable
public class GuideVersionKey {
private long versionNumber;
private long guide;
...
}


So, I have a GuideVersion class and this class has a composite key. Its composite key is composed by the id of a Guide and a versionNumber, both long numbers.


I just want to make a relation between GuideVersion and GuideVersionLang, as you can see in the code. However, I'm having problems on the @JoinColumns annotation:



@JoinColumns({
@JoinColumn(name="GUIDE_VERSION_NUMBER", referencedColumnName="VERSION_NUMBER"),
@JoinColumn(name="GUIDE_ID", referencedColumnName="GUIDE_ID")
})


I don't know why but the @JoinColumns is not working. I'm getting this error:



The @JoinColumns on the annotated element [field guideVersion] from the entity class [class com.model.GuideVersionLang] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.



As you can see in the code, I am specifying both @Id columns inside the @JoinColumns annotation. What am I missing here?


Thank you VERY much!




Aucun commentaire:

Enregistrer un commentaire