私は休止状態のプロジェクトがあり、テーブルを自動作成したいと思います。テーブルがすでに作成されている場合は、Entityクラスに新しいフィールドを追加してから、テーブルのデータを削除せずにテーブルに新しいフィールドを作成したいと考えています。hibernateプロジェクトからテーブルを自動作成できません
hibernate.cfg.xmlの
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="Inventory" package="com.mycompany.testhibernate"/>
</session-factory>
</hibernate-configuration>
EntityClass
package com.mycompany.testhibernate;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Inventory implements Serializable {
private Integer id;
private String itemName;
private String itemNote;
private Integer quantity;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getItemName() {
return this.itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemNote() {
return itemNote;
}
public void setItemNote(String itemNote) {
this.itemNote = itemNote;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public int getQuantity() {
return this.quantity;
}
}
Uは、MySQLのバージョンを使用していますか? –
mysqlバージョン5.6 – Riyad