troubleshooting Question

Hibernate composite key biderectional one-to-many association

Avatar of btocakci
btocakciFlag for Turkey asked on
Java EEJava
9 Comments1 Solution1532 ViewsLast Modified:
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?
Mick Barry
Java Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2010

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros