Exemplo n.º 1
0
  /**
   * 插入Person表
   *
   * @throws SQLException
   */
  private void testInserPerson(Session db) throws SQLException {
    Person p1 = new Person();
    p1.setAge(22);
    p1.setBirthDay(new Date());
    p1.setCell("135gg876");
    p1.setGender("M");
    p1.setHomeTown("BEIJING");
    p1.setLastModified(new Date());
    p1.setName("爸爸" + StringUtils.randomString());
    p1.setSchoolId(2);
    p1.setPhone("(083-2233)88778800");
    db.insert(p1);

    Person p2 = new Person();
    p2.setAge(22);
    p2.setBirthDay(new Date());
    p2.setCell("13506877");
    p2.setGender("M");
    p2.setHomeTown("BEIJING");
    p2.setLastModified(new Date());
    p2.setName("JinWang" + StringUtils.randomString());
    p2.setPhone("(083-87ss0");
    p2.setSchoolId(3);
    // p2.setPhoto(new File("c:/NTDETECT.COM"));
    db.insert(p2);

    Person p3 = new Person();
    p3.setAge(22);
    p3.setBirthDay(new Date());
    p3.setCell("1350ff876");
    p3.setGender("M");
    p3.setHomeTown("BEIJING");
    p3.setLastModified(new Date());
    p3.setName("儿子" + StringUtils.randomString());
    p3.setPhone("(083-28800)");
    p3.setSchoolId(2);
    p3.setParentId(1);
    db.insert(p3);

    assertEquals(1, p1.getId().intValue());
    assertEquals(2, p2.getId().intValue());
    assertEquals(3, p3.getId().intValue());
    //		System.out.println(JSON.toJSONString(Arrays.asList(p1,p2,p3)));
  }
Exemplo n.º 2
0
 @Test
 public void testInsertCascade() throws SQLException {
   Transaction db = this.db.startTransaction();
   List<School> schools = db.selectAll(School.class);
   School s = schools.get(0);
   Person p = new Person();
   p.setAge(12);
   p.setBirthDay(new Date());
   p.setCell("123433454");
   p.setFriendComment(new String[] {"AA"});
   p.setGender("M");
   p.setLastModified(new Date());
   p.setParentId(1);
   p.setSchool(s);
   p.setName("刘备");
   p.setSchoolId(3);
   db.insertCascade(p);
   System.out.println(p.getSchoolId());
   db.rollback(true);
 }