-->
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: Invalid Path
PostPosted: Sat Feb 18, 2006 4:29 pm 
Beginner
Beginner

Joined: Thu Dec 08, 2005 12:18 pm
Posts: 21
Location: Birmingham, Alabama
I am trying to follow a simple tutorial that queries a MySQL database using Hibernate3.0. Thisi s my first Hibernate program and I'm trying to learn Hibernate. I am not really sure what the error is telling me....

I am developing under Eclipse3.1 using MyEclipse workbench 4.1.

All the mapping files and configuration files are generated.

Hibernate version: 3.0

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
    <class name="com.rrcorp.hibernate.Catalog" table="catalog" catalog="test">
        <id name="catalogId" type="integer">
            <column name="CatalogId" />
            <generator class="native" />
        </id>
        <property name="journal" type="string">
            <column name="Journal" length="25" />
        </property>
        <property name="publisher" type="string">
            <column name="Publisher" length="25" />
        </property>
        <property name="date" type="string">
            <column name="Date" length="25" />
        </property>
        <property name="title" type="string">
            <column name="Title" length="45" />
        </property>
        <property name="author" type="string">
            <column name="Author" length="25" />
        </property>
    </class>
</hibernate-mapping>

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

Code:
public static Session currentSession() throws HibernateException {
        Session session = (Session) threadLocal.get();

      if (session == null || !session.isOpen()) {
         if (sessionFactory == null) {
            try {
               cfg.configure(CONFIG_FILE_LOCATION);
               sessionFactory = cfg.buildSessionFactory();
            } catch (Exception e) {
               System.err
                     .println("%%%% Error Creating SessionFactory %%%%");
               e.printStackTrace();
            }
         }
         session = (sessionFactory != null) ? sessionFactory.openSession()
               : null;
         threadLocal.set(session);
      }

        return session;
    }

Full stack trace of any exception that occurs:

Code:

[14:07:23,484] [INFO ] [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
[14:07:23,484] [INFO ] [SessionFactoryImpl] Checking 0 named queries
[14:07:23,984] [ERROR] [PARSER] *** ERROR:  Invalid path: 'Catalog.CatalogId'
[14:07:24,000] [ERROR] [PARSER] *** ERROR:  Invalid path: 'Catalog.Publisher'
[14:07:24,015] [ERROR] [PARSER] *** ERROR:  Invalid path: 'Catalog.Title'
[14:07:24,046] [ERROR] [[jsp]] Servlet.service() for servlet jsp threw exception
org.hibernate.hql.ast.QuerySyntaxError: Invalid path: 'Catalog.CatalogId' [SELECT Catalog.CatalogId, Catalog.Journal,Catalog.Publisher,Catalog.Date,Catalog.Title,Catalog.Author FROM com.rrcorp.hibernate.Catalog ]
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
   at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:920)
   at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
   at com.rrcorp.hibernate.CatalogService.getCatalogList(CatalogService.java:33)
   at org.apache.jsp.AddJournal_jsp._jspService(org.apache.jsp.AddJournal_jsp:126)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:595)
Caused by:  Invalid path: 'Catalog.CatalogId'
   at org.hibernate.hql.ast.LiteralProcessor.lookupConstant(LiteralProcessor.java:85)
   at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:172)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
   at org.hibernate.hql.ast.DotNode.resolveSelectExpression(DotNode.java:531)
   at org.hibernate.hql.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:474)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1527)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1467)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1041)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:380)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   ... 33 more


Name and version of the database you are using:
MySQL 5.0

The generated SQL (show_sql=true):

Code:
SELECT Catalog.CatalogId, Catalog.Journal,Catalog.Publisher,Catalog.Date,Catalog.Title,Catalog.Author FROM com.rrcorp.hibernate.Catalog

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 18, 2006 5:25 pm 
Beginner
Beginner

Joined: Thu Dec 08, 2005 12:18 pm
Posts: 21
Location: Birmingham, Alabama
I solved a part of my problem by looking at the query i was using.
As soon as a used a substitute for the table name, the error changed to something more readable.




Code:
[15:17:07,125] [ERROR] [[jsp]] Servlet.service() for servlet jsp threw exception
org.hibernate.QueryException: could not resolve property: CatalogId of: com.rrcorp.hibernate.Catalog [SELECT c.CatalogId, c.Journal,c.Publisher,c.Date,c.Title,c.Author FROM com.rrcorp.hibernate.Catalog c]
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
   at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
   at org.hibernate.hql.ast.FromElementType.getPropertyType(FromElementType.java:273)
   at org.hibernate.hql.ast.FromElement.getPropertyType(FromElement.java:349)
   at org.hibernate.hql.ast.DotNode.getDataType(DotNode.java:474)
   at org.hibernate.hql.ast.DotNode.prepareLhs(DotNode.java:208)
   at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:166)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
   at org.hibernate.hql.ast.DotNode.resolveSelectExpression(DotNode.java:531)
   at org.hibernate.hql.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:474)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1527)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1467)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1041)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:380)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
   at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:920)
   at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
   at com.rrcorp.hibernate.CatalogService.getCatalogList(CatalogService.java:33)
   at org.apache.jsp.AddJournal_jsp._jspService(org.apache.jsp.AddJournal_jsp:126)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
   at java.lang.Thread.run(Thread.java:595)


SQL:
Code:
SELECT c.CatalogId, c.Journal,c.Publisher,c.Date,c.Title,c.Author FROM com.rrcorp.hibernate.Catalog c


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 18, 2006 7:28 pm 
Beginner
Beginner

Joined: Sun Oct 16, 2005 12:37 pm
Posts: 47
Location: Romania, Galati
Use lower case for first letter for each property of instance of mapping class in your hql.

Not c.CatalogId but c.catalogId


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 18, 2006 10:43 pm 
Beginner
Beginner

Joined: Thu Dec 08, 2005 12:18 pm
Posts: 21
Location: Birmingham, Alabama
Yes this fixed my problem and I was able to get to the database. Thank you very much Tony. :-)

What I learned was use the names for the attributes from the mapping file name instead of the names from the table withing the datebase for any query. (Table in MySQL used a captial letter for the attribute Names)

[b]SQL:[\b]
Code:
SELECT c.catalogId,c.journal,c.publisher,c.date,c.title,c.author FROM Catalog c



However I am getting another exception. The name of my databse is "test". The name of the table is "catalog". This one is really off the wall. Where is Hibernate getting the test.test__catalog description from?

[code]
[20:25:29,093] [WARN ] [JDBCExceptionReporter] SQL Error: 1146, SQLState: 42S02
[20:25:29,093] [ERROR] [JDBCExceptionReporter] Table 'test.test__catalog' doesn't exist
[20:25:29,109] [ERROR] [[jsp]] Servlet.service() for servlet jsp threw exception
org.hibernate.exception.SQLGrammarException: could not execute query using iterate
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:432)
at org.hibernate.hql.ast.QueryTranslatorImpl.iterate(QueryTranslatorImpl.java:281)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:935)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at com.rrcorp.hibernate.CatalogService.getCatalogList(CatalogService.java:33)
at org.apache.jsp.AddJournal_jsp._jspService(org.apache.jsp.AddJournal_jsp:126)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Table 'test.test__catalog' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1252)
at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:411)
... 30 more
[\code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 19, 2006 3:26 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 12:37 pm
Posts: 47
Location: Romania, Galati
Remove

catalog="test"

from every mapping file.

Not
<class
name="Catalog"
table="Catalog"
catalog="test">
but
<class
name="Catalog"
table="catalog">


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 19, 2006 8:36 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 12:18 pm
Posts: 21
Location: Birmingham, Alabama
Tony:

Thank you very much..... That worked and I am getting the information back........


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.