btocakci
asked on
Hibernate composite key biderectional one-to-many association
I have 4 entities.
PaperDesign is bidirectionally associated with BoxPaperRela as One-To-Many.
They both have three-column-composite-key and these keys should be used as foreign key betwwen them. BoxPaperRelaId and PaperDesignId are embedded key entities of them (and attached in question)
When I set boxPaperRela in PaperDesign entity and saveOrUpdate the PaperDesignObject Hibernate generates as SQL such below:
select boxpaperre_.box_id, boxpaperre_.box_version, boxpaperre_.page_number, boxpaperre_.paper_id, boxpaperre_.paper_version, boxpaperre_.create_date as create6_7_,
boxpaperre_.paperDesign_pa ge_number as paperDes8_7_, boxpaperre_.paperDesign_pa per_id as paperDes9_7_, boxpaperre_.paperDesign_pa per_versio n as paperDe10_7_, boxpaperre_.relation_id as relation7_7_
from test.box_paper_rela boxpaperre_
where boxpaperre_.box_id=? and boxpaperre_.box_version=? and boxpaperre_.page_number=? and boxpaperre_.paper_id=? and boxpaperre_.paper_version= ?
Problem is boxpaperre_.paperDesign_pa per_id and successive column list. An exception is thrown since these columns can not befound. (org.hibernate.exception.S QLGrammarE xception: could not retrieve snapshot:)
In some way paperDesign attribute and its columns are used for selection though it is not correct. How to fix this problem?
entities-q.zip
PaperDesign is bidirectionally associated with BoxPaperRela as One-To-Many.
They both have three-column-composite-key
When I set boxPaperRela in PaperDesign entity and saveOrUpdate the PaperDesignObject Hibernate generates as SQL such below:
select boxpaperre_.box_id, boxpaperre_.box_version, boxpaperre_.page_number, boxpaperre_.paper_id, boxpaperre_.paper_version,
boxpaperre_.paperDesign_pa
from test.box_paper_rela boxpaperre_
where boxpaperre_.box_id=? and boxpaperre_.box_version=? and boxpaperre_.page_number=? and boxpaperre_.paper_id=? and boxpaperre_.paper_version=
Problem is boxpaperre_.paperDesign_pa
In some way paperDesign attribute and its columns are used for selection though it is not correct. How to fix this problem?
entities-q.zip
ASKER
they are alias names for that tables which have been generated by Hibernate.
I see, the second table name is alias
There are many discussions which looks relevant to your situation, perhaps you saw them, e.g.
http://openjpa.208410.n2.nabble.com/OneToMany-ManyToOne-Bidirectional-Composite-Key-BUG-td210672.html
There are many discussions which looks relevant to your situation, perhaps you saw them, e.g.
http://openjpa.208410.n2.nabble.com/OneToMany-ManyToOne-Bidirectional-Composite-Key-BUG-td210672.html
try specifying mappedBy attribute in your mapping
ASKER
mappedBy to where?
the property representing the other side of the mappin, 'paperContent' I think it is
ASKER
i tried it on paperDesign property but failed. Other side is paperDesign property.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no solution for me.
tables test.box_paper_rela and test.paper_design in the code and
test.box_paper_rela and boxpaperre_ in the query. So the second table is different altogether - is it OK?