我對這個問題的解決辦法是添加下面的權利之前,我創造我的實體管理器:
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/?user=" + DB_USER);
Statement stmt = connection.createStatement();
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS " + DB_NAME);
你要麼需要圍繞與一個try/catch塊或添加拋出的SQLException符號來它存在的功能。因此,舉例來說,這裏是我的initEntityManager
功能:
public static void initEntityManager() throws SQLException {
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/?user=" + DB_USER);
Statement stmt = connection.createStatement();
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS " + DB_NAME);
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = emf.createEntityManager();
}
看到http://opensource.atlassian.com/projects/hibernate/browse/HHH-1853 – Bozho 2010-10-15 12:55:57
雖然我理解的意圖,我覺得這是一個非常糟糕的主意。就個人而言,我不會使用與創建數據庫的用戶相同的用戶。 – 2010-10-15 13:30:27