-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Loading child table gives error
PostPosted: Wed Oct 21, 2009 10:07 am 
Newbie

Joined: Thu Sep 24, 2009 9:38 am
Posts: 2
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:
Code:
<class name="com.mhc.sandp.msa.app.beans.article.Article"
          table="(SELECT A.*,(SELECT B.CATEGORY_NAME FROM MSA_CATEGORY B WHERE A.ARTICLE_CODE=B.CATEGORY_CODE)ARTICLE_CODE_DESC
               FROM ARTICLE A)" >
      <id name="articleId" column="ARTICLE_ID"></id>
<property....../>
<set name="articleAttachments" batch-size="200" lazy="true">
         <key column="ARTICLE_ID" />
         <one-to-many class="com.mhc.sandp.msa.app.beans.article.ArticleAttachments"  />
</set>   
<class name="com.mhc.sandp.msa.app.beans.article.ArticleAttachments" table="ARTICLE_ATTACHMENTS">
        <composite-id name="id" class="com.mhc.sandp.msa.app.beans.article.ArticleAttachmentsId">
            <key-property name="articleId" column="ARTICLE_ID" />
            <key-property name="attachmentName" column="ATTACHMENT_NAME" />
        </composite-id>   
      <property name="attachment" column="ATTACHMENT" />
    </class>

articleattachments and articleattachmentsid bean are as follows:
Code:
public class ArticleAttachmentsId implements Serializable {
private Long articleId;
   private String attachmentName;
   
   public ArticleAttachmentsId(){}
   
   public ArticleAttachmentsId(Long articleId, String attachmentName){
      this.articleId=articleId;
      this.attachmentName=attachmentName;
   }

   public Long getArticleId() {
      return articleId;
   }

   public void setArticleId(Long articleId) {
      this.articleId = articleId;
   }

   public String getAttachmentName() {
      return attachmentName;
   }

   public void setAttachmentName(String attachmentName) {
      this.attachmentName = attachmentName;
   }
   
   public String toString(){
       StringBuffer sb = new StringBuffer();
       sb.append(" articleId="+articleId);
       sb.append(" attachmentName="+attachmentName);
       return sb.toString();
    }      
}

public class ArticleAttachments implements Serializable{

   private static final long serialVersionUID = -1893810557780172873L;
   private ArticleAttachmentsId id;
   private byte[] attachment;
   
   public ArticleAttachments(){}
   
   public ArticleAttachments(ArticleAttachmentsId id,byte[] attachment){
      this.id=id;
      this.attachment=attachment;
   }
   
   public ArticleAttachmentsId getId() {
      return id;
   }
   public void setId(ArticleAttachmentsId id) {
      this.id = id;
   }
   public byte[] getAttachment() {
      return attachment;
   }
   public void setAttachment(byte[] attachment) {
      this.attachment = attachment;
   }
   
   public String toString(){
       StringBuffer sb = new StringBuffer();
       sb.append(" MsaArticleAttachId="+id);
       sb.append(" attachment="+attachment);
       return sb.toString();
    }      
   
}


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

Code:
List<ArticleAttachments> content = new ArrayList<ArticleAttachments>();

            DetachedCriteria detachedcriteria = DetachedCriteria.forClass(ArticleAttachments.class);

            detachedcriteria.createAlias("id", "id");

            detachedcriteria.add(Restrictions.eq("id.articleId", articleId));

            detachedcriteria.add(Restrictions.eq("id.attachmentName", attachmentName));

            content.addAll(getHibernateTemplate().findByCriteria(detachedcriteria));

            return content.get(0);
[code]

I get the following exception:
[code]
Caused by: org.hibernate.QueryException: could not resolve property: articleId of: com.mhc.sandp.msa.app.beans.article.ArticleAttachments

      at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)

      at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)

      at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1379)

      at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)

      at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1354)

      at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:434)

      at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:394)

      at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:45)

      at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)

      at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:90)

      at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:59)

      at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)

      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)

      at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)


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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.