Hibernate is not auto-creating a table that does not exist in the DB

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 02:14:44

I had the same issue, this worked for me -

<property name="hibernate.hbm2ddl.auto">create</property>

The following scenario could be another reason why Hibernate cannot auto-create your table:

@Entity
public class Employee {
  @Id
  @GeneratedValue
  private String empID;
  private String name;
}   

The table Employee will not be auto-created by Hibernate since empID is a String and it has the @GeneratedValue annotation. empID should be an int or long. I had this problem sometime and I changed my id field that had the @GeneratedValue annotation to be of type int and Hibernate auto-created the table.

Carloso

I had the same problem, I solved it by changing:

org.hibernate.dialect.MySQLInnoDBDialect

to

org.hibernate.dialect.MySQLDialect

I found the solution in this question.

Why don't you try create or create-drop instead. Seems to serve your purpose. http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional

Dipayan Das
  1. First, check your MySQL version with $mysql --version $mysql Ver 14.14 Distrib 5.5.11

Then change Dialect accordingly

  1. then change the dialect property /For this example I have given MySQL55Dialect/ org.hibernate.dialect.MySQL55Dialect

//////////////////////////////////////////////// --where you can find Dialect:

org.hibernate.dialect
try 
import org.hibernate.dialect.ctrl+space
you find option

Hope this Help

I had the same issue, but for me the solution was:

<property name="hibernate.hbm2ddl.auto">create-drop</property>

instead of

<property name="hibernate.hbm2ddl">create-drop</property>

Hibernate can create table, hibernate sequence and tables used for many-to-many mapping on your behalf but you have to explicitly configure it by calling setProperty("hibernate.hbm2ddl.auto", "create") of Configuration object. By Default it just validate the schema with DB and fail if anything not already exist by giving error "ORA-00942: table or view does not exist".

For the existing working environment, or for any big application area, it's not recommended to set hibernate.hbm2ddl.autoon create or create-drop , as it is shown below

<property name="hibernate.hbm2ddl.auto">create-drop</property>

though it works, but it will drop all the existing tables of the database every time you restart the server.

If you are using the hibernate jar version 5.2.0 then please switch to either lower or any other version.This version jar is having some issue regarding update.

It worked for me and i hope it will work for others too.

Just do correct configuration

1) Create, Every time a new table will create. All Old data will be deleted.

<property name="hibernate.hbm2ddl.auto">create</property>

2) Update, If any modification has done then same will reflect to DB.

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