-->
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.  [ 6 posts ] 
Author Message
 Post subject: Simple HQL count(*) failing..
PostPosted: Sun Feb 26, 2006 4:21 pm 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
I am familiar with mapping and all of that stuff but this piece of HQL is driving me crazy. I made up this quick chunk of code to count the number of events for a given Course.

-- before this I initialize hibSession and it's ok
String hql = "Select count(*) from EVENT where COURSE_ID = :cid";
Query q1 = hibSession.createQuery(hql).setLong("cid",41);
List theList = q1.list();

When I run it I get an exception:

org.hibernate.hql.ast.QuerySyntaxException: EVENT is not mapped. [Select count(*) from EVENT ee where ee.COURSE_ID = :cid]

What type of mapping is the error referring to?

Here also is the debug output
2006-02-26 14:18:34,408 DEBUG AST - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'from'
| | \-[RANGE] 'RANGE'
| | +-[IDENT] 'EVENT'
| | \-[ALIAS] 'ee'
| \-[SELECT] 'Select'
| \-[COUNT] 'count'
| \-[ROW_STAR] '*'
\-[WHERE] 'where'
\-[EQ] '='
+-[DOT] '.'
| +-[IDENT] 'ee'
| \-[IDENT] 'COURSE_ID'
\-[COLON] ':'
\-[IDENT] 'cid'


Thanks in adv..


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 26, 2006 5:15 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Make sure the EVENT is mapped and post you're mapping file for this class.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 26, 2006 10:50 pm 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
Here is the mapping for EVENT

<?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="com.gcms.businessobjects.Event" table="EVENT">
<id name="dbid" type="long" unsaved-value="0">
<column name="ID" />
<generator class="native"/>
</id>
<property name="title">
<column name="TITLE" />
</property>
<property name="eventDate" type="date">
<column name="EVENT_DATE" />
</property>
<property name="eventType">
<column name="EVENT_TYPE" />
</property>
<property name="startTime" type="time">
<column name="START_TIME" />
</property>

<many-to-one name="course" column="COURSE_ID" unique="false" lazy="false" cascade="none" not-null="false" class="com.gcms.businessobjects.Course"/>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 2:50 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Try Event instead of EVENT. I'm not sure about case sensitivity but HQL definitely expects an entity name, not a table name.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 11:35 am 
Newbie

Joined: Sun Sep 21, 2003 11:22 pm
Posts: 8
Location: St. Paul, Minnesota
As wierd as it sounds, that worked - changing EVENT to Event to match the name of the Class!

Thanks..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 2:48 pm 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Doesn't sound weird to me (I'm not weird am I ? :)
Glad I could help.


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