我真的想知道更多有关更新,导出和可以提供给hibernate.hbm2ddl.auto
我需要知道何时使用更新的值的更多信息,何时不知道?还有什么选择?
这些是可能发生在DB上的变化:
在每种情况下,最佳解决方案是什么?
是否可以从Java创建MySQL数据库?
我只看到了这样的连接URL示例,其中在URL中指定了数据库名称:
String url="jdbc:mysql://localhost:3306/test";
Connection con = DriverManager.getConnection( url, "cb0", "xxx" );
Run Code Online (Sandbox Code Playgroud)
当我只有登录名和密码时,如何创建MySQL数据库?
我有以下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="connection.url">jdbc:mysql://localhost:3306/userdb</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<mapping class="com.beingjavaguys.hbn.User" />
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
我尝试了另一种方言(org.hibernate.dialect.MySQLDialect),但我看到了旧的结果
pom.xml中:
...
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> …Run Code Online (Sandbox Code Playgroud)