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_page_number as paperDes8_7_, boxpaperre_.paperDesign_paper_id as paperDes9_7_, boxpaperre_.paperDesign_paper_version 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_paper_id and successive column list. An exception is thrown since these columns can not befound. (org.hibernate.exception.SQLGrammarException: 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
Perhaps it is something obvious, I don't have much experince with hibernate, but I see
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?
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
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?