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
大家帮帮我啊谢谢了
<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
大家帮帮我啊谢谢了
解决方案 »
- struts2问题
- Hibernate Table 映射大小写敏感问题??
- eclipse swt/jface/RCP 学习网址积累[转载]
- 如何搭建Track+的运行环境
- 如何将list列表中一个位置不固定的人名提取出来,插入到第一位,其他人名依次后排!
- 两个应用服务器如何放到同一个事务单元里?
- getElementById的问题
- 编码gbk的不可映射字符,需要class或interface
- using static language or dynamic language?
- 记录一个单词在一个文件中出现的次数:程序怎么写呀?????
- 关于java.sql.SQLException的错误,刚开始不报错!不知道为什么就报错了,从起服务后又好了!请高手指点,小生谢过
- 用js递归xml文件遇到的问题!!!!
<generator class="uuid"> </generator>
</id>
sqlserver中主键生成器uuid好像不能用吧,改为identity试试
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也不行
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);
}}
id int identity primary key,
name varchar(30)
)报错:服务器: 消息 156,级别 15,状态 1,行 1
在关键字 'user' 附近有语法错误。很明显user是关键字,不可创建user表,换名字吧