Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error while mapping to child table directly

 
JayaSiji Gopal
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic