-->
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.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.hql.ast.QuerySyntaxException
PostPosted: Fri Nov 21, 2008 8:50 pm 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Hi all,

I think my question is an easy way to earn credits ;-).

My problem is:

org.hibernate.hql.ast.QuerySyntaxException: Country is not mapped [from Country where visible=true order by name]

Here is my tomcat log:
Code:
...
2008-11-21 22:36:06,671 [main] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
2008-11-21 22:36:06,718 [main] INFO  org.springframework.web.context.support.XmlWebApplicationContext - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@19214b1: display nam
e [Root WebApplicationContext]; startup date [Fri Nov 21 22:36:06 CET 2008]; root of context hierarchy
2008-11-21 22:36:06,796 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
2008-11-21 22:36:06,843 [main] INFO  org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationC
ontext@19214b1]: org.springframework.beans.factory.support.DefaultListableBeanFactory@102679a
2008-11-21 22:36:06,906 [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBea
nFactory@102679a: defining beans [dataSource,sessionFactory,txManager,countryDAOBeanTarget,countryDAOBean,languageDAOBeanTarget,languageDAOBean,userDAOBeanTarget,userDAOBean,locationDAOBeanTarget,loca
tionDAOBean]; root of factory hierarchy
2008-11-21 22:36:06,953 [main] INFO  org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: com.mysql.jdbc.Driver
2008-11-21 22:36:07,031 [main] INFO  org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
2008-11-21 22:36:07,046 [main] INFO  org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
2008-11-21 22:36:07,046 [main] INFO  org.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.username=wontsay, hibernate.connection.password=****, hi
bernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/project?characterEncoding=UTF-8, hibernate.bytecode.use_reflection_optimizer=false, hibern
ate.connection.driver_class=com.mysql.jdbc.Driver}
2008-11-21 22:36:07,046 [main] INFO  org.hibernate.cfg.Environment - Bytecode provider name : javassist
2008-11-21 22:36:07,062 [main] INFO  org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2008-11-21 22:36:07,140 [main] INFO  org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
2008-11-21 22:36:07,234 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.project.service.data.Country
2008-11-21 22:36:07,281 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity com.project.service.data.Country on table country
2008-11-21 22:36:07,390 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.project.service.data.Language
2008-11-21 22:36:07,390 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity com.project.service.data.Language on table language
2008-11-21 22:36:07,390 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.project.service.data.User
2008-11-21 22:36:07,390 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity com.project.service.data.User on table user
2008-11-21 22:36:07,421 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.project.service.data.Location
2008-11-21 22:36:07,421 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity com.project.service.data.Location on table location
2008-11-21 22:36:07,500 [main] INFO  org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.project.service.data.Country.user -> user
2008-11-21 22:36:07,500 [main] INFO  org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.project.service.data.User.location -> location
2008-11-21 22:36:07,515 [main] INFO  org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
2008-11-21 22:36:07,515 [main] INFO  org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean - Building new Hibernate SessionFactory
2008-11-21 22:36:07,515 [main] INFO  org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Se
arch is not enabled.
2008-11-21 22:36:07,531 [main] INFO  org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2008-11-21 22:36:07,953 [main] INFO  org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.0.67-community
2008-11-21 22:36:07,953 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-l
evel cache is not recommended)
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Connection release mode: auto
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
2008-11-21 22:36:07,984 [main] INFO  org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Query cache: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Statistics: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
2008-11-21 22:36:08,000 [main] INFO  org.hibernate.cfg.SettingsFactory - Named query checking : enabled
2008-11-21 22:36:08,046 [main] INFO  org.hibernate.impl.SessionFactoryImpl - building session factory
2008-11-21 22:36:08,375 [main] INFO  org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2008-11-21 22:36:08,421 [main] INFO  org.springframework.orm.hibernate3.HibernateTransactionManager - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@52eef4] of Hibernate
SessionFactory for HibernateTransactionManager
2008-11-21 22:36:08,515 [main] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1844 ms
21.11.2008 22:36:09 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8400
21.11.2008 22:36:09 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
21.11.2008 22:36:09 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31  config=null
21.11.2008 22:36:09 org.apache.catalina.startup.Catalina start
INFO: Server startup in 9841 ms
2008-11-21 22:36:28,625 [http-8400-1] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
2008-11-21 22:36:28,640 [http-8400-1] DEBUG org.hibernate.transaction.JDBCTransaction - begin
2008-11-21 22:36:28,640 [http-8400-1] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: true
2008-11-21 22:36:28,640 [http-8400-1] DEBUG org.hibernate.transaction.JDBCTransaction - disabling autocommit
2008-11-21 22:36:28,640 [http-8400-1] INFO  com.project.service.data.CountryHibernateDAO - List all countries.
2008-11-21 22:36:28,718 [http-8400-1] DEBUG org.hibernate.hql.ast.QueryTranslatorImpl - parse() - HQL: from Country where visible=true order by name
2008-11-21 22:36:28,734 [http-8400-1] DEBUG org.hibernate.hql.ast.AST - --- HQL AST ---
\-[QUERY] 'query'
    +-[SELECT_FROM] 'SELECT_FROM'
    |  \-[FROM] 'from'
    |     \-[RANGE] 'RANGE'
    |        \-[IDENT] 'Country'
    +-[WHERE] 'where'
    |  \-[EQ] '='
    |     +-[IDENT] 'visible'
    |     \-[TRUE] 'true'
    \-[ORDER] 'order'
       \-[IDENT] 'name'

2008-11-21 22:36:28,734 [http-8400-1] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
2008-11-21 22:36:28,781 [http-8400-1] DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker - select << begin [level=1, statement=select]
2008-11-21 22:36:28,796 [http-8400-1] ERROR com.project.service.data.CountryHibernateDAO - Can not list all countries.
org.hibernate.hql.ast.QuerySyntaxException: Country is not mapped [from Country where visible=true order by name]
        at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
        at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
        at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
        at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
        at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
        at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
        at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
        at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
        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:94)
        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:1650)
        at com.project.service.data.CountryHibernateDAO.listAll(CountryHibernateDAO.java:32)
        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:310)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy14.listAll(Unknown Source)
        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 flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:406)
        at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
        at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1417)
        at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:878)
        at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:121)
        at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
        at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:49)
        at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
        at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:146)
        at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:274)
        at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:377)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
...


I use hibernate3 annotions with the following configuration:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

  <hibernate-configuration>
    <session-factory>
      <!--
        thread is the short name for org.hibernate.context.ThreadLocalSessionContext
        and let Hibernate bind the session automatically to the thread
      -->
      <property name="current_session_context_class">thread</property>

      <!-- this will show us all sql statements -->
      <property name="hibernate.show_sql">true</property>

      <!-- mapping files -->
      <mapping class="com.project.service.data.Country"/>
      <mapping class="com.project.service.data.Language"/>
      <mapping class="com.project.service.data.User"/>
      <mapping class="com.project.service.data.Location"/>
      
    </session-factory>
  </hibernate-configuration>


My session factory and services (applicationcontext.xml):
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
  <!-- Datasource -->
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://localhost:3306/project?characterEncoding=UTF-8"/>
      <property name="username" value="wantsay"/>
      <property name="password" value="wontsay"/>
  </bean>

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="annotatedClasses">
         <list>
            <value>com.project.service.data.Country</value>
            <value>com.project.service.data.Language</value>
            <value>com.project.service.data.User</value>
            <value>com.project.service.data.Location</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
         </props>
    </property>
    <property name="dataSource">
       <ref bean="dataSource"/>
    </property>
  </bean>

   <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
         <ref local="sessionFactory"/>
      </property>
   </bean>

   <!-- country service -->

   <bean id="countryDAOBeanTarget" class="com.project.service.data.CountryHibernateDAO">
      <property name="sessionFactory" ref="sessionFactory"/>
   </bean>

   <bean id="countryDAOBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager" ref="txManager" />
      <property name="target" ref="countryDAOBeanTarget" />
      <property name="transactionAttributes">
         <props>
          <prop key="create*">PROPAGATION_REQUIRED</prop>
           <prop key="update*">PROPAGATION_REQUIRED</prop>
           <prop key="delete*">PROPAGATION_REQUIRED</prop>
           <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
         </props>
      </property>
   </bean>
   
   <!-- user service -->
   
   <bean id="userDAOBeanTarget" class="com.project.service.data.UserHibernateDAO">
      <property name="sessionFactory" ref="sessionFactory"/>
   </bean>

   <bean id="userDAOBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager" ref="txManager" />
      <property name="target" ref="userDAOBeanTarget" />
      <property name="transactionAttributes">
         <props>
           <prop key="create*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
         </props>
      </property>
  </bean>
 
</beans>


I use annotations in my Java POJOs.
The User class:
Code:
...
@Entity
@Table(name="user")
public class User  implements java.io.Serializable {

...
   
    @ManyToOne(fetch = FetchType.EAGER)
    private Country country;
   
...


The Country class:

Code:
@Entity(name="country")
public class Country  implements java.io.Serializable {

   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name = "country_id", nullable = false)
    private long countryId;
   
   @Column(nullable = false, length=50)
    private String name;
   
    @Column(name="numerical_code", nullable = true, length=5)
    private String numericalCode;
   
    @Column(name="iso_alpha_3", nullable = true, length=5)
    private String isoAlpha3;
   
    @Column(nullable = false)
    private boolean visible;
   
    @Column(nullable = false, length=14)
    private String created;
   
    @Column(name="last_modified", nullable = false, length=14)
    private String lastModified;
   
    public Country() {}


I can ask for a list of users above the users DAO:
Code:
@SuppressWarnings("unchecked")
   public Collection<User> listAll() {
      logger.info("List all users.");
      Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
      try {
         Collection<User> users = session.createQuery("from User").list();
         return users;
      } catch (HibernateException e) {
         logger.error("Can not list all users.", e);
         throw SessionFactoryUtils.convertHibernateAccessException(e);
      } catch (Exception e) {
         logger.error("Can not list all users.", e);
      }
      return new Vector<User>();
   }


But an exception will thrown when I ask for a plain list of countries:

Code:
@SuppressWarnings("unchecked")
   public Collection<Country> listAll() {
      logger.info("List all countries.");
      Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
      try {
         Collection<Country> countries = session.createQuery("from Country where visible=true order by name").list();
         for (Iterator<Country> i = countries.iterator(); i.hasNext(); ) {
            logger.info("Found country: " + i.next().getName() );
         }
         return countries;
      } catch (HibernateException e) {
         logger.error("Can not list all countries.", e);
         throw SessionFactoryUtils.convertHibernateAccessException(e);
      }
   }


To remember you to the failure:

org.hibernate.hql.ast.QuerySyntaxException: Country is not mapped [from Country where visible=true order by name]

I don't know why this failure was thrown, because the naming of the classes is correct - the Java class names were used in the queries. But if I ask for a plain country list the exception was thrown. Do I need a reverse mapping to users from country. I don't need the mapping in the logical way and I tried this above a OneToMany mapping whitout solving the problem.

Please tell me my failure...

Thx a lot,
Nepumuk


Top
 Profile  
 
 Post subject: solved, but need explanation
PostPosted: Sat Nov 22, 2008 8:08 am 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
Hi,

I solved the problem. I have to use the complete java class name in the query including the package name instead of the short class name:

Code:
...
Collection<Country> countries = session.createQuery("from com.project.service.data.Country where visible=true order by name").list();
...


But I do not understand why the short name works for the User entity:

Code:
...
Collection<User> users = session.createQuery("from User").list();
...


Any ideas what I have to change to use generally the short names?
(There is not another Country class in the project - so there can't be naming conflicts...)

Thx,
Nepumuk


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 22, 2008 8:44 am 
Newbie

Joined: Sun Nov 16, 2008 8:28 pm
Posts: 14
Location: Hamburg
I found my failure in the entity annotation:

Code:
@Entity(name="country")

vs.

@Entity
@Table(name="user")


Ohhhhhhhh shit, so many hours for this bug!!!

Can I rate my own answer ;-)...

Hopefully that this helps anybody,
Nepumuk


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