It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes error while mapping to child table directly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "error while mapping to child table directly" Watch "error while mapping to child table directly" New topic
Author

error while mapping to child table directly

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
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.


SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Sep 27, 2004
Posts: 303
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error while mapping to child table directly
 
Similar Threads
Composite primary key-Exception:could not resolve property
Criteria Qurey for Composite key table
Hibernate: Criteria Query with Subselect
problem with hibernate criteria
Help with Criteria API