-->
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.  [ 8 posts ] 
Author Message
 Post subject: Table Querys
PostPosted: Tue Sep 23, 2003 7:47 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I'm trying to make a query on a simple MySQL database but i'm having some problems. I try this two commands:


1) List result = session.find ("from TestObject where name='joao'");

2) List result = session.find ("from TestObject as obj where obj.name='A'");


The first command works fine, but in the second command, which should be equal, i got the following error:

"could not resolve property type: Name"

This way i can only make querys on a single table, which is very big limitation. What am i doing wrong?

Thanks in advance,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 8:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Its actually much more helpful if you give us the full stack trace of the exception rather than some paraphrase of it.

This is not the correct way to query. You should utilize parameters:
Code:
List result1 = session.find ("from TestObject where name=:name", Hibernate.STRING, "joao");
List result2 = session.find ("from TestObject as o where o.name=:name, Hibernate.STRING,"A");


Top
 Profile  
 
 Post subject: Full Stack Trace
PostPosted: Tue Sep 23, 2003 9:13 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Here is the full stack trace:


Handling ace_case.persistency.services.XeServiceRequestGetDock from ace_case.mar.system.services.XeServicer@523df with transaction <ace_case.mar.system.transactions.XeTransaction@1762027>

net.sf.hibernate.QueryException: could not resolve property type: name [from ace_case.persistency.storable.TestObject as obj where obj.name='joao']

at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:235)

at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:281)

at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:366)

at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:393)

at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:279)

at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)

at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:120)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)

at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)

at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)

at ace_case.persistency.XeStorageDockImpl.view(XeStorageDockImpl.java:136)

at ace_case.persistency.services.XeServiceHandlerGetDock.execute(XeServiceHandlerGetDock.java:31)

at ace_case.mar.system.services.XeServiceSyncExecutor.execute(XeServiceSyncExecutor.java:28)

at ace_case.mar.system.services.XeServicer.request_service_internal(XeServicer.java:194)

at ace_case.mar.system.services.XeServicer.request_service(XeServicer.java:105)

at ace_case.mar.tools.simulator.UI.XeUIServiceSimulatorControler.processEventInternal(XeUIServiceSimulatorControler.java:60)

at ace_case.mar.UI.components.XeUIControler.processEvent(XeUIControler.java:68)

at ace_case.mar.tools.simulator.UI.XeUIServiceSimulatorViewer$2.actionPerformed(XeUIServiceSimulatorViewer.java:117)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
What is your mapping for TestObject; specifically what does the "name" property mapping like like?

What happens if you use the correct query synatx (using parameters)?


Top
 Profile  
 
 Post subject: Mapping
PostPosted: Tue Sep 23, 2003 9:50 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
This is my testObject mapping file:

<class
name="ace_case.persistency.storable.TestObject"
table="objects">

<id
name="objId"
column="Id">
<generator class="native"/>
</id>

<property
name="objName"
column="Name"
type="string"
not-null="true"
unique="true"/>
</class>


When i try to use this query in MySQL prompt
--- select * from objects as obj where obj.name='joao'; ---
it works fine. But in hibernate it throws an exception i described.

Thanks again for helping me,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 10:20 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
I remember having the same issue last week... I even tried both of the main ways of writing the find...

------------------------------------------------------------------------------------
result = session.find("from property in class Property where property.MatterID = ?", new Long(MatterID), Hibernate.LONG);

-vs-

Query q = session.createQuery("select c from " + Property.class.getName() + " as c where c.MatterID = :matterID ");
q.setString("matterID", "" + MatterID);

result = q.list();
------------------------------------------------------------------------------------
I found that this happened because the the way I had mapped the tables to my (JAXB) objects in the .hbm file. I had made a mistake by not doing the foreign key relationship right.

Also, the argument you use to retrieve it on may be the property name (objName), and not the column name (Name). I'm sure Steve can comment on this...I'm still a bit of a noob. :P

-G


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 11:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Brannor hit it on the head.

You are attempting to query based on the column name rather than the java object property name. In the first instance it worked because you did not have an HQL alias before it, so Hibernate passed it as-is to the DB.

The two queries should actually be:
Code:
List result1 = session.find ("from TestObject where objName=:name", Hibernate.STRING, "joao");
List result2 = session.find ("from TestObject as o where o.objName=:name, Hibernate.STRING,"A");


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Tue Sep 23, 2003 11:24 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
It's working. Thanks a lot!

;)


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