-->
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.  [ 4 posts ] 
Author Message
 Post subject: QuerySyntaxException: TABLE is not mapped
PostPosted: Sat Mar 10, 2007 7:23 am 
Newbie

Joined: Fri Feb 23, 2007 12:42 pm
Posts: 5
Hibernate version:3.2.2.ga and JBoss 4.1 - NetBeans 5.5 - MySql 5

stack trace of any exception that occurs:
Code:
11:36:14,666DEBUG SecurityAssociation:143 - Using ThreadLocal: false
11:36:14,715DEBUG Client:514 - invoke called, but our invoker is disconnected, discarding and fetching another fresh invoker for: InvokerLocator [socket://127.0.0.2:3873/]
11:36:14,715DEBUG SocketClientInvoker:275 - connect called for: org.jboss.remoting.transport.socket.SocketClientInvoker@15d56d5
javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: USR is not mapped [SELECT DISTINCT OBJECT(k) FROM USR k WHERE k.username = ?1]
...

Caused by: org.hibernate.hql.ast.QuerySyntaxException: USR is not mapped [SELECT DISTINCT OBJECT(k) FROM USR k WHERE k.username = ?1]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)


My EJB3 method

Code:
    public Usr getUsrByUsername(String _username) throws UsernameException {
            if(_username==null) throw new UsernameException("The username value cannot be null.");
            Usr user = (Usr)em.createQuery("SELECT DISTINCT OBJECT(k) " +
                    "FROM USR k WHERE k.username = ?1").getSingleResult();
            return user;
        }




Persistence.xml


Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
        <persistence-unit name="Users-EJBModulePU" transaction-type="RESOURCE_LOCAL">
            <!-- Jboss uses hibernate as default persistence engine
            <provider>org.hibernate.ejb.HibernatePersistence</provider> -->
            <jta-data-source>java:/MySqlDS</jta-data-source>
            <exclude-unlisted-classes>false</exclude-unlisted-classes>
            <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                <!-- Show and print nice SQL on stdout -->
                <property name="hibernate.show_sql" value="true"/>
                <property name="hibernate.format_sql" value="true"/>
                <!-- Drop and create a new DB each time - Use only on development-->
                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            </properties>
        </persistence-unit>
    </persistence>




I'm using annotations
Code:
    @Entity
    @Table(name="USR")
    public class Usr implements java.io.Serializable {


Anyone can tell me where I'm making the mistake?
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 11:17 am 
Newbie

Joined: Fri Feb 23, 2007 12:42 pm
Posts: 5
I'm trying some test, like: em.persist(user);

and I get this
javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: eu.virtualLab.users.model.Usr

Do I need a mapping file even if I'm using annotations?

And to be onest, I expected Hibernate to create the table for me, but it didn't. What's wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 5:06 am 
Newbie

Joined: Fri Feb 23, 2007 12:42 pm
Posts: 5
Well, I just hope that some day I will benifit from all this time that I spending to study during the weekends.

The problem was actually in the persistence.xml
Note that I'm using as IDE NetBeans 5.5, App.Server JBoss 4.0.5 GA (EJB3), Hibernate embedded in JBoss and Annotations.

This file works properly
Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="Users-EJBModulePU" transaction-type="RESOURCE_LOCAL">
        <!-- Jboss uses hibernate as default persistence engine
            <provider>org.hibernate.ejb.HibernatePersistence</provider> -->
        <jta-data-source>java:/MySqlDS</jta-data-source>
        <class>eu.virtualLab.users.model.Usr</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
          <!-- Show and print nice SQL on stdout -->
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.format_sql" value="true"/>
          <!-- Use it just in development -->
          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
      </persistence-unit>
    </persistence>



I'm going to the pub now.


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: TABLE is not mapped
PostPosted: Mon Dec 06, 2010 7:44 pm 
Newbie

Joined: Mon Dec 06, 2010 7:35 pm
Posts: 1
Please check out this page

http://www.zabada.com/tutorials/hiberna ... xample.php

You need to map class files even when you are using Annotations.

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">

<props>
<!--YOUR HIBERNATE PROPERTIES HERE...-->
</props>
</property>
<property name="annotatedClasses">
<list>

<value>com.zabada.springrecipes.hibernatejpa.entity.Track</value>
<value>com.zabada.springrecipes.hibernatejpa.entity.Record</value>
<value>com.zabada.springrecipes.hibernatejpa.entity.Artist</value>
</list>

</property>
</bean>


I hope this solves the Table is not mapped problem.


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