• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

error while mapping to child table directly

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • 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: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!