日期:2014-05-19  浏览次数:20832 次

hibernate 配置文件在SQL上不能生成表
22:12:13,031 DEBUG SchemaExport:303 - drop table User
22:12:13,046 DEBUG SchemaExport:288 - Unsuccessful: drop table User
22:12:13,046 DEBUG SchemaExport:289 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'User' 附近有语法错误。
create table User (id varchar(255) not null, name varchar(255) null, pass varchar(255) null, createTime datetime null, expireTime datetime null, primary key (id))
22:12:13,046 DEBUG SchemaExport:303 - create table User (id varchar(255) not null, name varchar(255) null, pass varchar(255) null, createTime datetime null, expireTime datetime null, primary key (id))
22:12:13,046 ERROR SchemaExport:274 - Unsuccessful: create table User (id varchar(255) not null, name varchar(255) null, pass varchar(255) null, createTime datetime null, expireTime datetime null, primary key (id))
22:12:13,046 ERROR SchemaExport:275 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'User' 附近有语法错误。
22:12:13,046 INFO SchemaExport:196 - schema export complete
22:12:13,046 DEBUG JDBCExceptionReporter:46 - SQL Warning
java.sql.SQLWarning: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to hibernate
at com.microsoft.jdbc.base.BaseWarnings.createSQLWarning(Unknown Source)
at com.microsoft.jdbc.base.BaseWarnings.get(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getWarnings(Unknown Source)
at org.hibernate.util.JDBCExceptionReporter.logAndClearWarnings(JDBCExceptionReporter.java:22)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.release(ManagedProviderConnectionHelper.java:42)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:212)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at com.zz.hibernate.ExportDB.main(Unknown Source)
这是报出来的错。在User 附件有语法错误

User.hbm.xml 代码:
<?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 >

<class name="com.zz.hibernate.User">
<id name="id">
<generator class="uuid"/>
</id>
<property name="name"></property>
<property name="pass"></property>
<property name="createTime"></property>
<property name="expireTime"></property>
</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.connection.url">
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hibernate
</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"></property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

<mapping resource="com/zz/hibernate/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
请高手指点!

------解决方案--------------------