Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error while mapping to child table directly

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following scenario:

Article table, which has all article related information.
A article can have one or more attachments, stored in article_attachments table.
Article_attachments has composite key for which we have articleAttachmentsId bean.

Following is the mapping in hbm.xml file:



articleattachments and articleattachmentsid bean are as follows:


I know the articleId and attachmentname and would like to retrieve the ATTACHMENT from the table. I wrote the following code:


I get the following exception:


Dont understand y it is searching for articleId in articleAttachments table, when i have created an alias? also trying to see if there is a resolution to this problem.
Please help. Any ideas.

Thank you!
Jayashree.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you need the alias(). Looking at your query I don't see why you need the alias at all.

What happens if you remove the createAlias() call?

Mark
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The articleId is present in ArticleAttachmentsId bean, a composite key in article_attachments table.
If I were to remove the alias, how would I let the bean know to look for articleId and attachment name in articleattachmentsid bean.

The attachment itself , a byte[] is in articleattachments bean.

I also tried this approach:



Here again i get the same exception as above.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

JayaSiji Gopal wrote:The articleId is present in ArticleAttachmentsId bean, a composite key in article_attachments table.
If I were to remove the alias, how would I let the bean know to look for articleId and attachment name in articleattachmentsid bean.

The attachment itself , a byte[] is in articleattachments bean.

I also tried this approach:



Here again i get the same exception as above.



because you have it mapped directly in the ArticleAttaments class as a composite id, so the id property is already there.

Have you removed it, detachedcriteria.createAlias("id", "id");
from your code and tried it yet?

Mark
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok..i do understand what you are saying...but if you remove the alias, how would i supply articleId & attachmentName as restrictions to the detached criteria.

I tried :



It still tries to look for articleId in articleAttachments, whereas it is actually present in ArticleAttachmentsId.
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic