hibernate中的配置。。
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=hibernate_first</property>   
        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>   
        <property name="hibernate.connection.username">sa</property>   
        <property name="hibernate.connection.password">sasa</property>    
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>   
<mapping resource="com/first/hibernateTest/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
User.hbm.xml中的配置<hibernate-mapping>
<class name="com.first.hibernateTest.User">
<id name="id">
<generator class="uuid"></generator>
</id>
<property name="name"></property>
<property name="password"></property>
<property name="createTime"></property>
<property name="expireTime"></property>
</class>
</hibernate-mapping>错误信息是20:46:23,218 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:sqlserver://localhost:1433;DatabaseName=hibernate_first, Isolation Level: 2
drop table User
20:46:23,250 DEBUG SchemaExport:303 - drop table User
20:46:23,250 DEBUG SchemaExport:288 - Unsuccessful: drop table User
20:46:23,250 DEBUG SchemaExport:289 - 关键字 'User' 附近有语法错误。
create table User (id varchar(255) not null, name varchar(255) null, password varchar(255) null, createTime varchar(255) null, expireTime varchar(255) null, primary key (id))
20:46:23,250 DEBUG SchemaExport:303 - create table User (id varchar(255) not null, name varchar(255) null, password varchar(255) null, createTime varchar(255) null, expireTime varchar(255) null, primary key (id))
20:46:23,250 ERROR SchemaExport:274 - Unsuccessful: create table User (id varchar(255) not null, name varchar(255) null, password varchar(255) null, createTime varchar(255) null, expireTime varchar(255) null, primary key (id))
20:46:23,250 ERROR SchemaExport:275 - 关键字 'User' 附近有语法错误。
20:46:23,250  INFO SchemaExport:196 - schema export complete
20:46:23,265 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
20:46:23,265  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:sqlserver://localhost:1433;DatabaseName=hibernate_first
大家帮帮我啊谢谢了

解决方案 »

  1.   

    贴hibernate创建表的那段代码,或者你的创建表的sql
      

  2.   

    <id name="id"> 
    <generator class="uuid"> </generator> 
    </id> 
    sqlserver中主键生成器uuid好像不能用吧,改为identity试试
      

  3.   

    package com.first.hibernateTest;import org.hibernate.cfg.Configuration;
    import org.hibernate.tool.hbm2ddl.SchemaExport;public class ExportDB {
    public static void main(String[] args) {
    //读取配置hibernate.hbm.xml文件(如不加方法configue将默认读取hibernate.properties)
    Configuration cfg=new Configuration().configure();
    //此类可将类生成表。。
    SchemaExport se=new SchemaExport(cfg);

    se.create(true,true);
    }}执行这一段代码就会自动创建吧??
    5楼我试了identity也不行
      

  4.   

    package com.first.hibernateTest;import org.hibernate.cfg.Configuration;
    import org.hibernate.tool.hbm2ddl.SchemaExport;public class ExportDB {
    public static void main(String[] args) {
    //读取配置hibernate.hbm.xml文件(如不加方法configue将默认读取hibernate.properties)
    Configuration cfg=new Configuration().configure();
    //此类可将类生成表。。
    SchemaExport se=new SchemaExport(cfg);

    se.create(true,true);
    }}
      

  5.   

    User是关键字吧?晕你把所有相关User的换成MyUser试试
      

  6.   

    你的意思是sql server本身对这个不支持???
      

  7.   

    在sql server里试了一下create table user (
    id int identity primary key,
    name varchar(30)
    )报错:服务器: 消息 156,级别 15,状态 1,行 1
    在关键字 'user' 附近有语法错误。很明显user是关键字,不可创建user表,换名字吧