Link to home
Start Free TrialLog in
Avatar of btocakci
btocakciFlag for Türkiye

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_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
Avatar of for_yan
for_yan
Flag of United States of America image

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?
Avatar of btocakci

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
Avatar of Mick Barry
try specifying mappedBy attribute in your mapping
mappedBy to where?
the property representing the other side of the mappin, 'paperContent' I think it is
i tried it on paperDesign property but failed. Other side is paperDesign property.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
no solution for me.