4

I am using Hibernate as ORM for my project. I use mysql Database
I have a table "Products" inside DB "catalog".
I have put the @Table(name="Products",schema="catalog") annotation for the entity Products in my application.

However when I try to run the application I get the below exception. Can you please help me resolve this issue?

Exception:  
        Exception in thread "main" org.hibernate.HibernateException: Missing table:Products
        at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1281)
        at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:508)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
        at org.eros.purchase.db.utils.HibernateUtil.configure(HibernateUtil.java:17)
        at Test.main(Test.java:14)

Any thoughts on how I can fix this?

6
  • The missing table identified is not Products but Users. Look at that mapping and table. Commented Sep 10, 2013 at 10:19
  • Exception is talking about different missing table - Users Commented Sep 10, 2013 at 10:19
  • Check your mapping class where you have mapped as user, which is not present in Database Commented Sep 10, 2013 at 10:26
  • I corrected the description. Actually I'm looking for "Products" itself. Commented Sep 10, 2013 at 10:40
  • Try by removing schema Commented Sep 10, 2013 at 11:41

4 Answers 4

3

Please update your hibernate.cfg.xml file by adding this property

<property name="hibernate.hbm2ddl.auto">create</property>
or 
<property name="hibernate.hbm2ddl.auto">update</property>
Sign up to request clarification or add additional context in comments.

Comments

1

I got the same exception from hibernate. In my case, it was because the database user was not properly authorized to see the tables. The tables were definitively there on the database.

After I assigned the roles db_datareader to the user for this database it worked.

However, in another case, where the tables weren't actually there, I got exactly the same exception from hibernate. I cases where the tables are there, I think hibernate might show no more information because of security reasons.

Comments

0

I think your mapping is referring to User table which is actually not in database. . so check your xml mapping of hibernate

2 Comments

My mapping is looking for "Products" itself.
I have fixed the description of the question.
0
package com.mypackage;
    import javax.persistence.Entity;//first check two annotations belong to right package
    import javax.persistence.Table;
    @Entity
    @Table(name = "Products",schema="catalog")
    public class Products{

    //entity attributes
    }

//second check mapping file (if use)i.e register Products class with right spelling // or third check Hibernate util if we are register mapping class like this

public class CustomHibernateUtil{


private static Configuration getConfiguration(){

configuration.addAnnotatedClass(Products.class);
return configuration;

}
}

1 Comment

I have specified the mapping in "hibernate.cfg.xml". Below is the mapping tag in the "hibernate.cfg.xml" file <mapping class="org.xyz.Products"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.