hibernate自动建表问题

周容 发布于 2014/09/05 11:35
阅读 283
收藏 0
这是我的映射表
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.kidy.entity">
<class name="Department" table="kidy_department">
<id name="departmentId">
            <generator class="native"/>
</id>
<property name="desc"/>
<property name="name"/>
<many-to-one name="parent" class="Department" column="parentId"></many-to-one>
<set name="children">
<key column="parentId"></key>
<one-to-many class="Department"/>
</set>
</class>
</hibernate-mapping>
这是我的hibernate.cfg.xml
<!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.MySQL5Dialect
</property>
<property name="connection.url">jdbc:mysql:///kidy</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- 配置连接池 -->
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.timeout">120</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 其他配置 -->
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!--<property name="hibernate.hbm2ddl.auto">create</property>
--><!-- 配置映射文件 -->
<mapping resource="com/kidy/entity/Role.hbm.xml" />
<mapping resource="com/kidy/entity/Department.hbm.xml" />
</session-factory>
</hibernate-configuration>
下面是报的错误   
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kidy.kidy_department' doesn't exist 
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    com.mysql.jdbc.Util.getInstance(Util.java:386)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
    com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    org.hibernate.loader.Loader.doQuery(Loader.java:802)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    org.hibernate.loader.Loader.doList(Loader.java:2533)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    org.hibernate.loader.Loader.list(Loader.java:2271)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    com.kidy.dao.impl.DepartmentDaoImpl.findAll(DepartmentDaoImpl.java:33)
    com.kidy.service.impl.DepartmentServiceImpl.findAll(DepartmentServiceImpl.java:25)
    com.kidy.action.DepartmentAction.list(DepartmentAction.java:20)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    
都没有自动创建表还报没有表的错误。况且我没有要建 'kidy.kidy_department' 这个表,我要建的是kidy_department'这个表,不知道那个kidy. 是那里来的?请求大神支援
加载中
0
ajavaloser
ajavaloser

kidy.kidy_department是因为你url里配的是jdbc:mysql:///kidy,组合起来就是这个啦

<property name="hibernate.hbm2ddl.auto">update</property> update估计会去检查一下表

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部