aspose file tools*
The moose likes Spring and the fly likes QuerySyntaxException (table is not mapped) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "QuerySyntaxException (table is not mapped)" Watch "QuerySyntaxException (table is not mapped)" New topic
Author

QuerySyntaxException (table is not mapped)

Gabriela Rios
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
Hi,

I'm getting this error and I don't know why. Could someone please take a look at it?

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Contact is not mapped [from Contact c]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:322)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
at com.sys.power.dao.hibernate.ContactDaoImpl.findAll(ContactDaoImpl.java:40)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy9.findAll(Unknown Source)
at com.sys.power.SpringHibernateSample.main(SpringHibernateSample.java:28)

This is my app-context.xml: I use H2 as my datasource.



CREATE TABLE contact (
ID int(11) NOT NULL AUTO_INCREMENT,
FIRST_NAME varchar(60) NOT NULL,
LAST_NAME varchar(40) NOT NULL,
BIRTH_DATE date,
VERSION int(11) NOT NULL DEFAULT '0',
UNIQUE KEY UQ_CONTACT_1 (FIRST_NAME,LAST_NAME),
PRIMARY KEY (ID)
);

That seems to work fine:

2012-06-06 14:50:42,559 INFO [org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory] - <Creating embedded database 'dataSource'>
2012-06-06 14:50:42,699 INFO [org.springframework.jdbc.datasource.init.ResourceDatabasePopulator] - <Executing SQL script from class path resource [META-INF/sql/schema.sql]>
2012-06-06 14:50:42,750 INFO [org.springframework.jdbc.datasource.init.ResourceDatabasePopulator] - <Done executing SQL script from class path resource [META-INF/sql/schema.sql] in 51 ms.>
2012-06-06 14:50:42,750 INFO [org.springframework.jdbc.datasource.init.ResourceDatabasePopulator] - <Executing SQL script from class path resource [META-INF/sql/test-data.sql]>
2012-06-06 14:50:42,760 INFO [org.springframework.jdbc.datasource.init.ResourceDatabasePopulator] - <Done executing SQL script from class path resource [META-INF/sql/test-data.sql] in 10 ms.>

This is Contact:



This is my ContactDaoImplementation



This should be my object type rather than my table name.
return sessionFactory.getCurrentSession().createQuery("from Contact c").list();

My main class


what's wrong with my code? What am I missing? :-(
Gabriela Rios
Ranch Hand

Joined: Feb 27, 2008
Posts: 32
I found my problem. I misspelled the package name somewhere. It seems like I just have to post here to 5 minutes later find the issue myself. I apologize. Thanks.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Was just about to ...

But thank you for commenting on the resolution.

Please mark as "resolved"

WP
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: QuerySyntaxException (table is not mapped)