I am using JBoss 4.0.3RC1 release with 'default' configuration. My database is MySQL 4.1. version and JDBC driver is "mysql-connector-java-3.1.10". My application is able to use the specified data source.
The error I get is:
javax.ejb.EJBException: null; CausedByException is:
lab_master is not mapped. [from lab_master]
at $Proxy116.getLabs(Unknown Source)
I have a table created "lab_master" in the "labuse" database or catalog of MySql. My entity bean class is BrcdLab annotated as @Entity and @Table(name="lab_master"). Auto generated integer Id is the key.
BrcdLabManager is the business interface implemented by a stateless session bean BrcdLanManagerBean where a call to "getLabs()" is implemented. The call simply returns a collection:
return em.createQuery("from lab_master").getResultList();
Reference "em" is to a @PersistentContext EntityManager as defined in persistence.xml.
The questions are:
- Why do I get "table not mapped" error?
- Error message is not revealing nor tells what could be done to solve the issue. How do we get more information about what is happening?
I searched the forum, but could not find any thread discussing "table not mapped" error issue. After loosing more than 2 days of worth, still trying to correct myself. Lack of information is frustrating. Ejb3Trailblazer runs for me and my tiny entity mapping is modelled on that example except the change of using MySQL instead of HYSQL as used in the example.
Any hints are welcome.
Well, it is always good to find answer to your question on your own. Yes, it was my mistake. Here is what happened:
I have an entity object named BrcdLab mapped to the table lab_master. In another bean where I was making query to get all records of this objects (all labs added in the table corresponding to BrcdLab); my EJB object query was referring to the table name. It was
"from lab_master l". It should be "from BrcdLab l" i.e. it should be the object in the query rather than the table name. It is satisfying to see that EJB 3.0 specs are consistent - once the trouble of mapping object to table is taken by the container provider; EJB wants us to consistently refer to Object names and not to the table name. That is why there is EJB based Object query language.
The bigger question is why this error occurred? The problem is in the example EJB3Trail blazer case, both table and object names are same! For example Fund object and Fund table; except for the lower case for the table name. That kind of makes it to miss this point when a beginner like me tries to build a tiny example off that sample. It would help if table and object names are slightly differentiated by some prefix or suffix. It is understandable that EJB3.0 wants developer to think table and object synonymously; but it leads to problem at times while implementation.
Hopefully, anyone visiting to this forum and facing this problem would find this explanation useful.
I had the same error and i am using the name of the object
instead the name of the table.
I can´t know what is going wrong.
your entity is not part of your persistence unit
10x a lot!
thank you, umeshgeeta!
I had the same problem and your explanation was the solution.
Table name and Class name Users
List list = session.createQuery("SELECT * FROM USERS).list();
Use HQL -> exception
List list = session.createSQLQuery("SELECT * FROM USERS).list();
Pure SQL -> work, with out problem
How is your class' name. Suppose it is
the your HQL-Code would look like
SELECT u FROM User u