-->
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.  [ 5 posts ] 
Author Message
 Post subject: could not resolve property: in Criteria Query (joined Table)
PostPosted: Fri Jan 11, 2008 1:31 pm 
Newbie

Joined: Mon Nov 07, 2005 11:30 am
Posts: 7
Hello,

i have a problem with searches in embedded(joined) Objects(tables).

Following Query works in Hibernate Console:

select abw.dbKey, abw.auftrag.kunde.kundenName
from de.test.pps.VoAbweichung abw
where abw.auftrag.kunde.kundenName like 'xyz%'

If i make the same in a Criteria Query, i get the errormessage
org.hibernate.QueryException: could not resolve property: auftrag.kunde.kundenName of: de.test.pps.VoAbweichung

Hibernate version:

hibernate 3.0.5

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="de.test.pps.VoAbweichung" table="Abweichung">
<meta attribute="class-description">
Repräsentiert eine Abweichung Datenbank
</meta>
<id name="dbKey" column="dbKey" type="integer" length="10" access="property">
<generator class="native"></generator>
</id>

<natural-id>
<property name="mandant" type="integer" column="mandant">
<meta attribute="use-in-tostring">true</meta>
</property>
<many-to-one name="auftrag" class="de.test.VoAuftrag" column="Auftrag" lazy="false"></many-to-one>
<many-to-one name="afo" class="de.test.VoArbeitsfolge" column="Arbeitsfolge" lazy="false" not-null="false"></many-to-one>

</natural-id>
<version name="version" column="version"></version>

<property name="beanstandeteMenge" type="integer" column="BeanstandeteMenge"></property>
<many-to-one name="vorgangAbgeschlossenVon" class="de.test.VoPersonal" column="abgeschlossen_von" lazy="false"></many-to-one>

</class>

</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="de.test.VoAuftrag" table="Auftrag">
<meta attribute="class-description">Repräsentiert einen Auftrag in der Datenbank </meta>
<id name="voAuftragKey" column="dbKeyAuftrag" type="integer" length="6" >
<generator class="native"></generator>
</id>

<natural-id>
<property name="mandant" type="integer" column="mandant" />
<property name="auftragsNummer" type="integer" column="Auftragsnummer"/>
</natural-id>

<version name="version" column="version" ></version>
<property name="teilLieferung" type="boolean"></property>
<property name="erledigt" type="java.lang.Boolean"></property>
<many-to-one name="kunde" class="de.test.VoKunde" column="kunde" lazy="false"></many-to-one>
<many-to-one name="teil" class="de.test.VoTeil" lazy="false">
<column name="teil"></column>
</many-to-one>

</class>

</hibernate-mapping>


<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="de.test.VoKunde" table="Kunde">
<meta attribute="class-description">
Repräsentiert einen Kunden in derDatenbank
</meta>
<id name="voKundeKey" column="dbKeyKunde" type="integer"
length="4">
<generator class="native"></generator>
</id>

<natural-id>
<property name="mandant" type="int" column="mandant">
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="kundenNummer" type="int"
column="kundennummer">
<meta attribute="use-in-tostring">true</meta>
</property>
</natural-id>
<version name="version" column="version"></version>
<property name="kundenName" type="string" not-null="true"
length="30">
<meta attribute="use-in-tostring">true</meta>
</property>

</class>
<!--many-to-one name="abteilung" class="de.test.VoAbteilung">
<column name="mandant"></column>
<column name="abteilungsnummer"></column>
</many-to-one>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Session session = getSessionFactory().openSession();
Criteria crit = session.createCriteria(searchFilter.getClassToFilter());
Iterator<Criterion> iter = searchFilter.getFilterConditions()
.iterator();
while (iter.hasNext()) {
Criterion filterCondition = iter.next();
crit.add(filterCondition);
}

List l = crit.list();
session.close();
return l;


Full stack trace of any exception that occurs:

org.hibernate.QueryException: could not resolve property: auftrag.kunde.kundenName of: de.test.VoAbweichung
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:63)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1086)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:403)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:369)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at de.test.ejb.GenericFactoryBean.searchExtended(GenericFactoryBean.java:665)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:130)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:139)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at de.leuka.pps.ejb.interceptor.SecurityInterceptor.invoke(SecurityInterceptor.java:66)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)


Name and version of the database you are using:

Mysql 4.1.14-nt

The generated SQL (show_sql=true):
-

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 4:06 pm 
Newbie

Joined: Fri Jan 11, 2008 3:53 pm
Posts: 1
Location: Anchorage, AK
Can you post the code for the Criteria query? Are you setting aliases for all members that aren't directly members of the queried class?

I've found that I have to create an alias for anything that isn't a direct member of the class. For example, if I have a class Foo with a member Foo.text and a mapping for Foo.Bar.msg I'd have to create an alias to Bar to get Bar.msg.

Example:
Code:
Criteria c = s.createCriteria(VoAbweichung.class);

c.createAlias("auftrag", "auft");
c.createAlias("auft.kunde", "knd");

c.add(Restrictions.ilike("knd.kundenName", "asjdlsadka"));


I believe this is the solution you're looking for. Of course these aliases may get a bit insane, so you should probably make nice constants for all of them like KUNDE_ALIAS.

I'm still not sure of the exact reason for having to do things like this in Criteria based queries. Perhaps a developer, or simply someone more knowledgeable than myself could chime in and give us some answers.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 19, 2008 4:42 pm 
Newbie

Joined: Mon Nov 07, 2005 11:30 am
Posts: 7
Hello,

i have testet your suggestion in a very experimental try.
I think, this will solve my problem.

I will post, when i have a stable solution.

Thank you so far.

best regards


Top
 Profile  
 
 Post subject: Problem solved
PostPosted: Wed Jan 30, 2008 5:32 pm 
Newbie

Joined: Mon Nov 07, 2005 11:30 am
Posts: 7
Hello,

thank you for the solution.
My Problem is solved with your suggestion.


Top
 Profile  
 
 Post subject: Re: could not resolve property: in Criteria Query (joined Table)
PostPosted: Sat May 28, 2011 7:04 pm 
Newbie

Joined: Sat May 28, 2011 7:02 pm
Posts: 1
This solved my problem too.

Thanks


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