一. hibernate的实体类有一定的规则,类似于mybatis的逆向工程导出的实体类.具体的规则以及原因如下: 1.持久化类需要提供无参的构造方法. 因为hibernate底层采用反射机制创建对象,采用class.newInstance()创建对象,此方法默认调用无参构造方法创建对象.如果我们只写一个带参数的构造函数在查询的时候会报错误 org.hibernate.InstantiationException 例如:我们重写一个类的无参构造方法: public class User { pr
1.把主键定义为自动增长标识符类型 在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值.例如: create table customers(id int auto_increment primary key not null, name varchar(15)); insert into customers(name) values("name1"),("name2"); select id from customers;
一.数据表名称为T_OFFICE,其主键为PID(number类型) 二.首先为数据表的PID字段创建序列 序列名称:S_T_OFFICE_PID 序列详细内容: 三.创建相应的触发器 触发器名称:T_OFFICETRIGER 触发器具体内容: create or replace TRIGGERHYMGS_INDUSTRY_FQ6.T_OFFICETRIGER BEFORE INSERT ON HYMGS_INDUSTRY_FQ6.T_OFFICE FOR EACH ROW BEGINselec
最近在搞一个电商系统中由于业务需求,需要在插入一条产品信息后返回产品Id,刚开始遇到一些坑,这里做下笔记,以防今后忘记. 类似下面这段代码一样获取插入后的主键 User user = new User(); user.setUserName("chenzhou"); user.setPassword("xxxx"); user.setComment("测试插入数据返回主键功能"); System.out.println("插入前主键为:
[相关链接:http://blog.csdn.net/bluishglc/article/details/7710738] 具体做法: 1:找两台服务器,分别配置: TicketServer1: auto auto TicketServer2: auto auto 例如:可以在全局global,本地session或者local动态设置这两个参数以控制auto_increment的增量与偏移量.本例在session中设置这二者的值: 具体做法是:1.1:修改自增量 mysql> set @@ses