We help IT Professionals succeed at work.
Get Started

Hibernate composite key biderectional one-to-many association

btocakci
btocakci asked
on
1,530 Views
Last Modified: 2012-05-11
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
Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE