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.  [ 2 posts ] 
Author Message
 Post subject: Enum mapping and criteria
PostPosted: Thu Apr 22, 2010 8:42 am 
Newbie

Joined: Thu Jan 04, 2007 4:40 am
Posts: 9
Hi,

I have two entities: "Parent" & "Child"

Child is mapped in Parent like this:

Code:
<many-to-one name="child" class="org.demo.Child"
         update="false" insert="false" embed-xml="false" node="chd/@id" >
         <column name="CHILD_ID" precision="10" scale="0"   not-null="true" />
      </many-to-one>


and Child has an Enum type mapped like this:

Code:
<property name="toyType">
         <column name="TOY_TYPE" length="100" />
         <type name="org.demo.type.LabelEnumType">
            <param name="enum">org.demo.ToyType</param>
            <param name="defaultLabel"></param>
         </type>
      </property>


mapped as a "String" in CHILD.TOY_TYPE column

Everything works fine but I cannot do this:

Code:
      DetachedCriteria dc = DetachedCriteria.forClass(Parent.class);
      dc.add(Restrictions.and(
               Restrictions.eq("child.id", childId),
               Restrictions.eq("child.toyType", ToyType.CAR)));
      dc.setProjection(Projections.rowCount());
      int count = DataAccessUtils.intResult(getHibernateTemplate().findByCriteria(dc));



because I got:

nested exception is org.hibernate.QueryException: could not resolve property: child.toyType of: org.demo.Parent

so it looks like it cannot solve:

parent->child->toyType

probably because ToyType has not an own "Entity", but it is embedded.

Is there any workaround for it? I need to continue using DetachedCriteria as it will be "decorated" in other places of the code.
So I'm wondering if I can solve that always using DetachedCriteria.

Thanks,
Rand


Top
 Profile  
 
 Post subject: Re: Enum mapping and criteria
PostPosted: Mon Apr 26, 2010 5:47 am 
Newbie

Joined: Thu Jan 04, 2007 4:40 am
Posts: 9
any idea?

Thanks,
Rand


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

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.