hibernate 配置

1.配置configuration参考文档 \hibernate-distribution-3.3.1.GA-dist\hibernate-distribution-3.3.1.GA\project\etc\hibernate.properies

2.让hibernate输出格式化的sql语句和配置与线程有关

 

当mysql表的id是自增的 在hibernate逆向生成表的对象时 选择id的增长方式为identity

 hibernate文档写道

  1、自动增长identity

适用于MySQL、DB2、MS SQL Server,采用数据库生成的主键,用于为long、short、int类型生成唯一标识
使用SQL Server 和 MySQL 的自增字段,这个方法不能放到 Oracle 中,Oracle 不支持自增字段,要设定sequence(MySQL 和 SQL Server 中很常用)
数据库中的语法如下:
MySQL:create table t_user(id int auto_increment primary key, name varchar(20));
SQL Server:create table t_user(id int identity(1,1) primary key, name varchar(20));

<id name="id" column="id" type="long">
<generator class="identity" />
</id>

 

posted @ 2016-01-27 22:30  been  阅读(200)  评论(0编辑  收藏  举报