many-to-many mapping
I am trying to do a many to many relationship mapping.
I have succesfully done a one to one relationship so I know some of the basics.
I have followed the roster example.
I am getting this strange error:
ErrorName :com.sun.enterprise.tools.verifier.tests.persistence.DefaultProviderVerification
Error Description : java.lang.StringIndexOutOfBoundsException: String index out of range: 3
at java.lang.String.substring(String.java:1765)
anyone know what this should be telling me?
# 2
It is me giving a (sortof) answer to my own question in the hopes it will help somone down the line.
I got it to work here is the working code:
//correct
@ManyToMany(targetEntity=com.mycompany.stereo.database.Accessory.class)
@JoinTable(name="STEREO_ACCESSORY",
joinColumns=
@JoinColumn(name="STEREOID"),
inverseJoinColumns=
@JoinColumn(name="ACCESSORYID")
)
public Set getAccessoryList() {
System.out.println("class: stereo, method:getAccessotyList");
return accessoryList;
}
the problem was I was adding this to the @JoinColumn anotation
@JoinColumn(name="STEREOID", referencedColumnName="id"),
If somone could explain what excactly the referencedColumnName means or does that would be great.
I thought it ment that column STEREOID in the "join table" (stereo_accessory) referenced the column id in the stereo table.
# 3
Hi stridersun,
Thanks for posting your solution. The JPA annotations are described in chapter 9 of the JPA specification, available at:
http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html
The specification has examples showing how annotations can be used. The @JoinColumn annotation is described in 9.1.6.