<!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.connection.url">
jdbc:sqlserver://localhost:1433; DatabaseName=test2?characterEncoding=utf-8
</property>
<property name="hibernate.connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">sa</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hbm2ddl.auto">create</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="com/test2/pojo/Yh.hbm.xml"/>
</session-factory>
</hibernate-configuration>
以上是hibernate.cfg.xml文件8:07:27,890  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
18:07:27,890  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to master
18:07:27,890  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
18:07:27,890  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将数据库上下文改为 'master'。
18:07:27,890  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
18:07:27,890  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to 简体中文
18:07:27,890  WARN JDBCExceptionReporter:48 - SQL Warning: 0, SQLState: 
18:07:27,890  WARN JDBCExceptionReporter:49 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]已将语言设置改为 简体中文。
18:07:27,890  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:sqlserver://localhost:1433; DatabaseName=test2?characterEncoding=utf-8
 感觉到奇怪的是,我想在数据库test2中建立表,系统却把表建在了master中
各位老大,这到底是怎么回事啊,什么愿意造成这种情况的呢

解决方案 »

  1.   

     你把url 改下
      我有个mysql的你参考下
        <property name="url" value="jdbc:mysql://localhost:3306/mytest"></property>
      

  2.   

     完整的配置如下,我的配置很正常,可以正常跑的
      LZ参考下吧
        
          <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
      <property name="url" value="jdbc:mysql://localhost:3306/mytest"></property>
      <property name="username" value="root"></property>
      <property name="password" value="123456"></property>
      <property name="maxActive" value="100"></property>
      <property name="maxIdle" value="30"></property>
      <property name="maxWait" value="500"></property>
      <property name="defaultAutoCommit" value="true"></property>
     </bean>
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="dataSource" ref="dataSource"></property>
       <property name="hibernateProperties">
         <props>
           <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
           <prop key="hibernate.show_sql">true</prop>
         </props>
       </property>
       <property name="mappingResources">
        <list>
          <value>com/test/bean/User.hbm.xml</value>
        </list>
       </property>
      </bean>
      <bean id="userDao" class="com.test.dao.impl.UserDAOImpl" scope="singleton">
         <property name="sessionFactory">
          <ref bean="sessionFactory"/>
         </property>
      </bean>
      <bean id="userService" class="com.test.service.impl.UserServiceImpl"> 
       <property name="userDao" ref="userDao"></property>
      </bean>
      <bean id="saveUserAction" class="com.test.action.user.SaveUserAction">
       <property name="service" ref="userService"></property>
      </bean>
        <bean id="listUserAction" class="com.test.action.user.ListUserAction" scope="prototype">
       <property name="service" ref="userService"></property>
      </bean>
       <bean id="removeUserAction" class="com.test.action.user.RemoveUserAction" scope="prototype">
         <property name="service" ref="userService"></property>
       </bean>
    </beans>
        
      

  3.   

    你这下面的不是hibernate的配置吧,是spring的配置吧,我要的是hibernate自动建表的文件啊,我有一个mysql的可以正常跑,但是这个sqlserver的不能正常运行啊
      

  4.   

    lz用的是sql数据库
    你们给他mysql数据库的配置
      

  5.   

    你可以直接反向工程生成这个啊。myeclipse。
      

  6.   

    估计是Yh.hbm.xml的问题,是不是这里要设置schem
      

  7.   

    解决了,呵呵,去掉后面的characterEncoding=utf-8,ok了