-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria.createAlias : QueryException on @Embedded values
PostPosted: Mon Nov 16, 2009 7:27 am 
Newbie

Joined: Mon Nov 16, 2009 7:18 am
Posts: 3
Hi, recently i discover my app always throws a Exception when searching with alias in @Embedded fields.

Like this.
Code:
@Embeddable
public class Contato {
//attrs
}

@Table
@Entity(name = "motorista")
public class Motorista {
@Embedded
private Contato contato;
}


And the following code:
Code:
   public static void main(String[] args) {
      Session s = HibernateUtil.openSession();
      Criteria crit = s.createCriteria(Motorista.class);
      crit.createAlias("contato", "contato");
      crit.add(Restrictions.like("contato.nome", "jo",
            MatchMode.ANYWHERE));
      System.out.println(crit.list().size());
   }

Throws this exception:
Code:
Exception in thread "main" org.hibernate.QueryException: could not resolve property: nome of: br.com.sistram.model.prestador.Motorista
   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)
   at br.com.sistram.util.DaoListPaginator.main(DaoListPaginator.java:160)

If i change to @OneToOne this code work perfectly, but i need a solution using the embedded values. Someone can help?

Ty.


Last edited by MarkyAmeba on Tue Nov 17, 2009 7:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Criteria createAlias doens't works with @Embedded values
PostPosted: Mon Nov 16, 2009 8:06 am 
Newbie

Joined: Mon Nov 16, 2009 7:18 am
Posts: 3
Even this code doens't work
Code:
Session s = HibernateUtil.openSession();
Criteria crit = s.createCriteria(Motorista.class);
crit.add(Restrictions.like("nome", "jo",   MatchMode.ANYWHERE));
System.out.println(crit.list().size());


There's no way to make this query using Criteria?


Top
 Profile  
 
 Post subject: Re: Criteria.createAlias : QueryException on @Embedded values
PostPosted: Wed Nov 18, 2009 6:40 am 
Newbie

Joined: Mon Nov 16, 2009 7:18 am
Posts: 3
Ok.. so it's a bug and should be reported.
Thanks for help and attention if anyone at least read this topic.

No solution yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.