-->
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.  [ 15 posts ] 
Author Message
 Post subject: Newbie question: getting some fields back from a persisted o
PostPosted: Wed Jun 08, 2005 1:12 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.x
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 package="com.txdx.pojo">
<class name="PatientPOJO" table="patients" lazy="false" >

<id name="id" column="patient_id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="salutation" type="string" length="4" not-null="true" />
<property name="firstName" type="string" length="25" not-null="true" />
<property name="initial" type="string" length="1" not-null="false"/>
<property name="lastName" type="string" length="25" not-null="true" />
<property name="suffix" type="string" length="3" not-null="false"/>
<property name="haddr1" type="string" length="35" not-null="true" />
<property name="haddr2" type="string" length="35" not-null="false"/>
<property name="hcity" type="string" length="15" not-null="true" />
<property name="hstate" type="string" length="2" not-null="true" />
<property name="hzip" type="string" length="10" not-null="true" />
<!-- other fields deleted for brevity -->

<property name="serialVersionUID" type="long"/>
<bag name="Rxs" cascade="all" inverse="true" lazy="false" order-by="rxDate">
<key column="patient_id"/>
<one-to-many class="com.txdx.pojo.RxPOJO"/>
</bag>
</class>

</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
// get context classloader
Thread cur = Thread.currentThread();
ClassLoader save = cur.getContextClassLoader();
cur.setContextClassLoader(getClass().getClassLoader());

// do usual hibernate thing
Session session = HibernateUtil.currentSession();
List patients = session.createQuery(
"select firstName, initial, lastName from Patient ").list();
Iterator iter = patients.iterator();

Full stack trace of any exception that occurs:
00:02:50,363 ERROR PARSER:35 - *** ERROR: Patient is not mapped.
Unhandled event loop exception
Reason:
No data type for node: org.hibernate.hql.ast.IdentNode
+-[IDENT] IdentNode: 'firstName' {originalText=firstName}

Name and version of the database you are using:
latest MySQL
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


OK, all I want to do is get a list of certain fields (first and last name, id, etc) for all rows in my table so the user can select a name to work on. They select a name, I use the id to do another lookup to get all the information on this person.

The documentation, although excellent as a reference, does not seem geared to someone just getting started.

When I bring up the hibernate console in eclipse, I get error messages about as meaningful (to me) as the one listed above. Things like "in expected", or with this code:
select firstName from Patient
I get
Error 2005-06-08 00:08:22.301 undefined alias: firstName [select firstName from Patient




]
org.hibernate.QueryException: undefined alias: firstName [select firstName from Patient

]


Can someone please show me a HQL statement that will give me a couple of fields so I can use something like the scalar results code shown in chapter 10 to make a collection to use in my gui? I just need to get my feet wet here.

Thanks for the help.

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 1:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/hib_docs/v3/re ... ing-scalar

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: this results in an "in expected" error message
PostPosted: Wed Jun 08, 2005 9:34 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Thanks for the pointer, but using that as an example I try this statement:
select p.firstName, p.lastName from Patient p group by p.lastName

and get the "in expected" message:
org.hibernate.QueryException: in expected: p [select p.firstName, p.lastName from Patient p group by p.lastName

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 9:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can't group something without a aggrgate function in the select clause.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: simpler statement is no better
PostPosted: Wed Jun 08, 2005 10:31 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
OK, I simplified it to the following:
select p.firstName, p.lastName from Patient p

and I still get this error.

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 10:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
"select p.description, p.price from Product p" works fine here.

Are you sure you dont have some mapping error ?

Check Error Log for stacktrace and show it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: stack trace
PostPosted: Wed Jun 08, 2005 10:45 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
I apologize for not sending this along in my last post...

org.hibernate.QueryException: in expected: p [select p.firstName,
p.lastName from Patient p




]
at org.hibernate.hql.classic.FromParser.token(FromParser.java:106)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at
org.hibernate.hql.classic.PreprocessingParser.end(PreprocessingParser.java:121)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:30)
at
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:172)
at
org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:148)
at
org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:410)
at
org.hibernate.impl.SessionFactoryImpl.getReturnTypes(SessionFactoryImpl.java:616)
at
org.hibernate.impl.AbstractQueryImpl.getReturnTypes(AbstractQueryImpl.java:448)
at org.hibernate.console.HQLQueryPage.getPathNames(HQLQueryPage.java:72)
at
org.hibernate.eclipse.console.views.QueryPageViewer.addColumnsToTable(QueryPageViewer.java:189)
at
org.hibernate.eclipse.console.views.QueryPageViewer.createTable(QueryPageViewer.java:164)
at
org.hibernate.eclipse.console.views.QueryPageViewer.createControl(QueryPageViewer.java:147)
at
org.hibernate.eclipse.console.views.QueryPageViewer.<init>(QueryPageViewer.java:105)
at
org.hibernate.eclipse.console.views.QueryPageTabView.rebuild(QueryPageTabView.java:78)
at
org.hibernate.eclipse.console.views.QueryPageTabView$1.contentsChanged(QueryPageTabView.java:47)
at
org.hibernate.eclipse.console.views.QueryPageTabView$1.intervalAdded(QueryPageTabView.java:52)
at
javax.swing.AbstractListModel.fireIntervalAdded(AbstractListModel.java:130)
at org.hibernate.console.QueryPageModel.add(QueryPageModel.java:50)
at
org.hibernate.console.KnownConfigurations$3.queryPageCreated(KnownConfigurations.java:167)
at
org.hibernate.console.ConsoleConfiguration.fireQueryPageCreated(ConsoleConfiguration.java:265)
at
org.hibernate.console.ConsoleConfiguration.executeHQLQuery(ConsoleConfiguration.java:246)
at
org.hibernate.eclipse.console.actions.ExecuteHQLAction.execute(ExecuteHQLAction.java:99)
at
org.hibernate.eclipse.console.actions.ExecuteHQLAction.run(ExecuteHQLAction.java:94)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:996)
at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:538)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
at
org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:441)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2921)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2554)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1601)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1565)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:315)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:230)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:371)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:160)
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:324)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:330)
at org.eclipse.core.launcher.Main.basicRun(Main.java:274)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why are you using the classic parser ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: classic parser?
PostPosted: Wed Jun 08, 2005 11:21 am 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
I didn't realize that I was, and I also don't know that that means.

I downloaded hibernate and put all the JARs in an Eclipse plug-in. I have also been compiling the source from CVS to get the latest hbm2ddl changes, but those JARs are in a separate plug-in and I am using them with an ant task local to that third plug-in.

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 11:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
somewhere you have hibernate.query.factory_class set to org.hibernate.hql.classic.ClassicQueryTranslatorFactory

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: hibernate.query.factory_class setting
PostPosted: Wed Jun 08, 2005 1:51 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
I searched the whole eclipse installation (including the workspace) and the string factory_class does not exist there in any file. Maybe this is default behavior? I am using Hibernate 3.0.2 according to the output when I get the sessionFactory. Where should I set this value?

--PK

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 2:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - maybe that one was default in 3.0.2 ...can't remember. anyway use the alpha4 release being released today.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: alternative to ClassicQueryTranslatorFactory?
PostPosted: Wed Jun 08, 2005 11:20 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 2:54 pm
Posts: 33
Location: Austin, TX
Rather than have it default to ClassicQueryTranslatorFactory, what value should I set the query.factory_class to myself? I probably need to learn to control this factor, anyway.

_________________
--Pierce Krouse


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 12:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Should work using either parser as this is a very simple query.
Looking at the mapping: try;

select p.firstName, p.lastName from PatientPOJO p


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 1:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
lol - of course. im getting blind ,)

_________________
Max
Don't forget to rate


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