一个自增长ID的对象被save或者persist后,会返回其主键ID: Department department = new Department(); department.setName("xxxxxxx"); session.persist(department); System.out.println("id = " + department2.getId()); Department department2 = new Department(); dep
网上搜了好多文章照着弄都返回不了主键给map, 实践证明要在传入的map参数里写回插入的主键,要这样写 <selectKey resultType="java.lang.Integer" order="BEFORE" keyProperty="col.id"> // keyProperty要指定为map参数的 名称.写回的键名 才行 SELECT SEQ_LOG.nextval AS id FROM DUA
public class Demo { public static void main(String[] args) { try { String sql="insert into person values(?,?)"; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn=DriverManager.getConnection("jdbc:sqlse