我的配置文件似乎有问题,但我真的不知道它可能是什么。
我以前使用hibernate 3.6,现在使用hibernate 4.2,有一些我忽略的重要更改,但是文档似乎没有更改这部分。
这是我的配置文件:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/Test</property>
<property name="connection.username">root</property>
<property name="connection.password">*****</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">10</property>
<property name="maxActive" value="10" />
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Mapping files -->
<mapping resource="database/config/mapping/test.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我的java源代码:
public class CreateDB {
public static void main(String argv[]){
try {
Configuration configuration = new Configuration();
configuration.configure("database/config/DBCreate.cfg.xml");
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration
.getProperties());
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
DBConnect.Disconnect(null, sessionFactory.openSession()); // Just logout from a session
} catch (Exception e) {
System.out.println("Database unreachable.");
}
}
}
这是返回语句:
mai 02, 2013 11:41:59 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
mai 02, 2013 11:41:59 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.0.Final}
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: database/config/DBCreate.cfg.xml
mai 02, 2013 11:41:59 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: database/config/DBCreate.cfg.xml
Database unreachable.
我真的不明白什么是错的,也许有人能启发我。抱歉可能造成干扰,如果我的帖子没有被改编,这是我的第一个。
此致。