hibernate连接mysql,出现这样的错误提示,数据库就是不自动建表
droptableifexistsUser22:24:30,927DEBUGSchemaExport:303-droptableifexistsUser22:24:30,...
drop table if exists User
22:24:30,927 DEBUG SchemaExport:303 - drop table if exists User
22:24:30,935 DEBUG JDBCExceptionReporter:40 - SQL Warning
java.sql.SQLWarning: Unknown table 'user'
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:722)
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:650)
at com.mysql.jdbc.Statement.getWarnings(Statement.java:1657)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:309)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:284)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:186)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at com.bjsxt.hibernate.ExportDB.main(ExportDB.java:15)
22:24:30,937 WARN JDBCExceptionReporter:48 - SQL Warning: 1051, SQLState: 42S02
22:24:30,937 WARN JDBCExceptionReporter:49 - Unknown table 'user'
create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,937 DEBUG SchemaExport:303 - create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,938 ERROR SchemaExport:274 - Unsuccessful: create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,938 ERROR SchemaExport:275 - Specified key was too long; max key length is 767 bytes
22:24:30,939 INFO SchemaExport:196 - schema export complete
22:24:30,939 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
22:24:30,939 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost:3306/hibernate_first 展开
22:24:30,927 DEBUG SchemaExport:303 - drop table if exists User
22:24:30,935 DEBUG JDBCExceptionReporter:40 - SQL Warning
java.sql.SQLWarning: Unknown table 'user'
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:722)
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:650)
at com.mysql.jdbc.Statement.getWarnings(Statement.java:1657)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:309)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:284)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:186)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at com.bjsxt.hibernate.ExportDB.main(ExportDB.java:15)
22:24:30,937 WARN JDBCExceptionReporter:48 - SQL Warning: 1051, SQLState: 42S02
22:24:30,937 WARN JDBCExceptionReporter:49 - Unknown table 'user'
create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,937 DEBUG SchemaExport:303 - create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,938 ERROR SchemaExport:274 - Unsuccessful: create table User (id varchar(255) not null, name varchar(255), password varchar(255), createTime datetime, expireTime datetime, primary key (id))
22:24:30,938 ERROR SchemaExport:275 - Specified key was too long; max key length is 767 bytes
22:24:30,939 INFO SchemaExport:196 - schema export complete
22:24:30,939 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
22:24:30,939 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost:3306/hibernate_first 展开
5个回答
展开全部
可能 是你的配置文件User有问题参考一下
<!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.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_first </property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="org/bai/du/vo/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
=============================
User.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="org.lzq.jxlt.vo.User" table="user">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" />
</property>
。
。
。
。
</class>
</hibernate-mapping>
<!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.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_first </property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="org/bai/du/vo/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
=============================
User.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="org.lzq.jxlt.vo.User" table="user">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" />
</property>
。
。
。
。
</class>
</hibernate-mapping>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
user是mysql的关键字,换个名字试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
为什么要用hibernate来建表呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
hbm2dll.auto属性设为true了么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询