hibernate连接SQL Server2000出错

chjttony 2008-09-04 12:31:16
请问各位大侠我的这个程序问题出在哪里?非常感谢
主程序
package com.hibernate;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class ExportDB {

public static void main(String[] args) {
//读取hibernate.cfg.xml配置文件
Configuration cfg=new Configuration().configure();

//创建SchemaExport
SchemaExport export=new SchemaExport(cfg);

//创建数据库表
export.create(true, true);
}

}

User类:
/**
*
*/
package com.hibernate;

import java.util.Date;


public class User {
private String id;

private String name;

private String password;

private Date createTime;

private Date expireTime;

/**
* @return the id
*/
public String getId() {
return this.id;
}

/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the name
*/
public String getName() {
return this.name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* @return the password
*/
public String getPassword() {
return this.password;
}

/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}

/**
* @return the createTime
*/
public Date getCreateTime() {
return this.createTime;
}

/**
* @param createTime the createTime to set
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}

/**
* @return the expireTime
*/
public Date getExpireTime() {
return this.expireTime;
}

/**
* @param expireTime the expireTime to set
*/
public void setExpireTime(Date expireTime) {
this.expireTime = expireTime;
}
}

hibernate映射文件
<?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.hibernate.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>

hibernate配置文件:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory name="foo">
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hibernate_simple</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

<mapping resource="com/hibernate/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
hibernate和SQL Server2000的驱动一切都配好了,运行一直报错“User附近有错误",数据库中也没有表创建,请各位大侠帮帮忙,非常感谢!!!
...全文
68 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
sd5816690 2008-09-04
  • 打赏
  • 举报
回复
user 是数据库保留关键词
在映射文件的 <class name="com.hibernate.User"> 中加上红色部分试试
<class name="com.hibernate.User" table="[user]">

如果不成功,就重新建表吧

设计数据库时,最好避免与系统变量重名
比如 user , name

改一下名称:userInfo、userName

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧