java - JPA - Resolving relationships (ManyToMany + ManyToOne) -
i've got problem defining relationships, i've got entities:
i've tryed make relationships in code, this:
project-datostabla
@manytomany(cascade = cascadetype.merge) @jointable(name = "datostabla", joincolumns = @joincolumn(name = "idproject", referencedcolumnname = "idproject"), inversejoincolumns = @joincolumn(name = "idtable", referencedcolumnname = "idtable")) public set<datostabla> getdatostabla() { return datostabla; }
datostabla-project
@manytomany(mappedby = "datostabla") public set<project> getproject() { return project; }
datostabla-atributosdatostabla
@onetomany(fetch = fetchtype.lazy, mappedby = "datostabla") public set<atributosdatostabla> getatributodatostabla() { return atributodatostabla; }
atributosdatostabla-datostabla
@manytoone(cascade = cascadetype.merge, fetch = fetchtype.lazy) @joincolumns({ @joincolumn(name = "idtable", referencedcolumnname = "idtable"), @joincolumn(name = "project", referencedcolumnname = "project") }) public datostabla getdatostabla() { return datostabla; }
when run application, got error:
caused by: org.hibernate.mappingexception: foreign key (fk40oq9lkjvyu5b4s0x9j69uop4:atributosdatostabla [idtable])) must have same number of columns referenced primary key (datostabla [idproject,idtable])
i've tryed make composite key in atributosdatostabla doing this: atributosdatostabla-datostabla
@manytoone(cascade = cascadetype.merge, fetch = fetchtype.lazy) @joincolumns({ @joincolumn(name = "idtable", referencedcolumnname = "idtable"), @joincolumn(name = "project", referencedcolumnname = "project") }) public datostabla getdatostabla() { return datostabla; }
and got error: caused by: org.hibernate.mappingexception: unable find column logical name: project in datostabla
so, i'm quite stuck @ moment. knows way solve problem?
Comments
Post a Comment