Hibernate : Help in resolving exception org.hibernate.HibernateException: Missing table

我是研究僧i 提交于 2019-12-23 12:27:44

问题


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?


回答1:


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>



回答2:


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




回答3:


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;

}
}



回答4:


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.



来源:https://stackoverflow.com/questions/18716204/hibernate-help-in-resolving-exception-org-hibernate-hibernateexception-missin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!