I'm trying to map two objects to each other using the ManyToMany association, but for some reason, when I use the mappedBy property, hibernate seems to be confused about what exactly I'm matching. The only difference in my comparison is that the association is not performed in the primary key field in one of the records (the field is unique, though).
Tables:
Sequence ( id NUMBER, reference VARCHAR, ) Project ( id NUMBER ) Sequence_Project ( proj_id number references Project(id), reference varchar references Sequence(reference) )
Objects look (annotations are on the getter, put them in fields to condense the bit):
class Sequence { @Id private int id; private String reference; @ManyToMany(mappedBy="sequences") private List<Project> projects; }
And own side:
class Project { @Id private int id; @ManyToMany @JoinTable(name="sequence_project", joinColumns=@JoinColumn(name="id"), inverseJoinColumns=@JoinColumn(name="reference", referencedColumnName="reference")) private List<Sequence> sequences; }
This is not thrown using the MappingException:
property-ref [_test_local_entities_Project_sequences] not found on object [test.local.entities.Project]
It seems weird to add the fully qualified class name, separated by an underscore. How can i avoid this?
EDIT: I played a little with this. Changing the name of the mappedBy property raises another exception, namely:
org.hibernate.AnnotationException: mappedBy refers to an unknown property of the target: test.local.entities.Project.sequences
So, the annotation is processed correctly, but for some reason the reference to the property is incorrectly added to the internal configuration of Hibernate.